8月11日的学习内容

今天主要是对8月11日学的文字性的知识用于编程中,让我们更好的去理解概念,编写程序,但是对于我来说,今天学习的知识让我头晕,我很容易搞混,以至于我编写程序速度慢,很容易出错,我们今天主要练习了学生管理系统的编程,虽然能写出来,但是还是有很多地方理解不彻底,模模糊糊的。

学生管理系统的程序:

package test4;
/**新建一个学生类*/
public class Student {
/**学号*/
public int code;
/**姓名*/
public String name;
/**成绩*/
public int score;
}


package test4;


import javax.swing.JOptionPane;


public class studentmanage1 {


public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "欢迎光临学生管理系统");
boolean a =login();
if(a==false){
JOptionPane.showMessageDialog(null, "非法用户");
}
while(true){
String x =JOptionPane.showInputDialog(null,"1、添加\n2、显示\n3、查找\n4、删除\n5、修改\n6、排序\n7、退出");
int b =Integer.parseInt(x);
switch(b){
case 1:
add();
break;
case 2:
show();
break;
case 3:
find();
break;
case 4:
del();
break;
case 5:
update();
break;
case 6:
sort();
break;
case 7:
JOptionPane.showMessageDialog(null, "退出");
System.exit(0);
default:
JOptionPane.showMessageDialog(null, "输入错误,请输入1——7");
}
}


}
/**登陆*/
public static boolean login(){
for(int i=0;i<3;i++){
String a =JOptionPane.showInputDialog(null,"请输入用户名");
String b =JOptionPane.showInputDialog(null,"请输入密码");
if(a.equals("123") && b.equals("456")){
return true;
}
else{
JOptionPane.showMessageDialog(null, "输入错误,请从新输入");
}
}
return false;
}
/**创建一个学生数组*/
public static Student[] stu =new Student[20];
/**创建一个静态变量*/
public static int number=0;
/**添加*/
public static void add(){
String x =JOptionPane.showInputDialog(null,"请输入需要添加的学生学号");
String y =JOptionPane.showInputDialog(null,"请输入需要添加的学生姓名");
String z =JOptionPane.showInputDialog(null,"请输入需要添加的学生成绩");

Student a =new Student();

a.code=Integer.parseInt(x);
a.name=y;
a.score=Integer.parseInt(z);

stu[number]=a;
number++;

}
/**显示*/
public static void show(){
String s ="学号   姓名   成绩\n";
for(int i=0;i<number;i++){
s+=stu[i].code+"  "+stu[i].name+"  "+stu[i].score+"\n";
}
JOptionPane.showMessageDialog(null, s);
}
/**方法*/
public static int Byname(){
String c =JOptionPane.showInputDialog(null,"请输入学生姓名");
for(int i=0;i<number;i++){
if(c.equals(stu[i].name)){
return i;
}
}
JOptionPane.showMessageDialog(null, "查无此人");
return -1;
}
/**查找*/
public static void find(){
int index=Byname();
if(index !=-1){
JOptionPane.showMessageDialog(null, stu[index].code+"   "+stu[index].name+"   "+stu[index].score);
}

}
/**删除*/
public static void del(){
int index=Byname();
if(index !=-1){
for(int i=index;i<number;i++){
stu[i]=stu[i+1];
}
number--;
}

show();
}
/**修改*/
public static void update(){
int index =Byname();
if(index !=-1){
String code =JOptionPane.showInputDialog(null,"请输入需要修改的学生学号");
String name =JOptionPane.showInputDialog(null,"请输入需要修改学生的姓名");
String score =JOptionPane.showInputDialog(null,"请输入需要修改学生的成绩");
stu[index].code=Integer.parseInt(code);
stu[index].name=name;
stu[index].score=Integer.parseInt(score);
}
show();
}
/**排序*/
public static void sort(){
for(int i=0;i<number;i++){
for(int j=i+1;j<number;j++){
if(stu[i].score<stu[i].score){
Student a=stu[i];
stu[i]=stu[j];
stu[j]=a;
show();

}
}
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值