student[j]=student[j+1];//将后面的值依次向前赋值
}
break;
}
System.out.println("没有此学号的学生!
");
}
}
2.4.3查询学生
publicvoidsearchStudent(Stringstuno){
for(inti=0;i<=studentNum;i++){
if(student[i].stuno.equals(stuno)){
System.out.println("查找成功!
");
System.out.println("学号:
"+student[i].stuno+"姓名:
"+student[i].name+
"数学成绩:
"+student[i].math+"英语成绩:
"+student[i].english+"语文成绩:
"
+student[i].chinese);
break;
}else{
System.out.println("没有此学号学生!
请重新查询");
}
}
}
2.4.4修改学生
publicvoidalterStudent(Stringstuno,Studenta){
for(inti=0;i<=studentNum;i++){
if(student[i].stuno.equals(stuno)){
System.out.println("修改后学号:
");
a.setStuno(input.nextLine());
System.out.println("修改后姓名:
");
a.setName(input.nextLine());
System.out.println("修改后数学成绩:
");
a.setMath(input.nextFloat());
System.out.println("修改后英语成绩:
");
a.setEnglish(input.nextFloat());
System.out.println("修改后语文成绩:
");
a.setchinese(input.nextFloat());
student[i]=a;
System.out.println("修改成功!
");
break;
}
System.out.println("没有此学号的学生!
");
}
}
2.4.5打印学生
publicvoidprintStudent(){
System.out.println(studentNum);
for(inti=0;i<=studentNum;i++){
if(student[i]!
=null){
System.out.println("学号:
"+student[i].stuno+"姓名:
"+student[i].name+
"数学成绩:
"+student[i].math+"英语成绩:
"+student[i].english+"语文成绩"
+student[i].chinese);
}
}
}
2.4.6统计学生
publicvoidinfoStudent(){
inti=0;
while(student[i]!
=null){
i++;
}
System.out.println("共用学生"+i+"名");
}
菜单栏:
publicstaticvoidmain(String[]args){
//TODO自动生成的方法存根
//菜单:
添加学生、删除学生,查找学生、修改学生、打印学生
//使用数组来实现对多个学生的管理
System.out.println("\n\n\t欢迎使用学生成绩管理系统");
System.out.println("**********************************");
System.out.println("1、添加学生\n2、删除学生\n3、查询学生\n4、修改学生\n5、打印学生\n6、统计学生\n7、退出系统");
booleanflag=true;
while(flag){
Studenta=newStudent();
StudentGuanlid=newStudentGuanli();
in2=newScanner(System.in);
System.out.println("输入你选择的功能:
");
ints=in2.nextInt();
switch(s){
case1:
System.out.println("输入你要添加学生的信息:
");
d.addStudent(a);
break;
case2:
System.out.println("输入你要删除的学生的学号:
");
Scannerst=newScanner(System.in);
Stringn=st.nextLine();
d.deleteStudent(n);
break;
case3:
System.out.println("输入你要查询的学生的学号:
");
Scannerst1=newScanner(System.in);
Stringhao=st1.nextLine();
d.searchStudent(hao);
break;
case4:
System.out.println("输入你要修改学生的学号:
");
Scannerst2=newScanner(System.in);
Stringxiu=st2.nextLine();
d.alterStudent(xiu,a);
break;
case5:
d.printStudent();
break;
case6:
d.infoStudent();
break;
default:
System.out.println("\t感谢使用学生管理系统!
");
flag=false;
break;
}
}
}
}
3源代码
类Student:
packagetest;
publicclassStudent{
//学号、姓名、3门课程“数学”、“英语”和“语文”的成绩,包括的方法有计算3门课程的“总分”、“平均分”、“最高分”及“最低分”
Stringstuno,name;//定义学号、姓名
floatmath,english,chinese;
publicStudent(Stringstuno,Stringname,floatmath,floatenglish,floatchinese){
this.stuno=stuno;
this.name=name;
this.chinese=chinese;
this.math=math;
this.english=english;
}
publicStudent(){
//TODO自动生成的构造函数存根
}
publicvoidsetStuno(Stringstuno){
this.stuno=stuno;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicvoidsetMath(floatmath){
this.math=math;
}
publicvoidsetEnglish(floatenglish){
this.english=english;
}
publicvoidsetchinese(floatchinese){
this.chinese=chinese;
}
publicStringgetStuno(){
returnthis.stuno;
}
publicStringgetName(){
returnthis.name;
}
publicfloatgetMath(){
returnmath;
}
publicfloatgetEnglish(){
returnenglish;
}
publicfloatgetchinese(){
returnchinese;
}
publicfloatsum(){
returnmath+english+chinese;
}
publicfloatavg(){
return(math+english+chinese)/3;
}
publicfloatmax(){
if(math>english){
if(math>chinese){
returnmath;
}else{
returnchinese;
}
}else{
if(english>chinese){
returnenglish;
}
else{
returnmath;
}
}
}
publicfloatmin(){
if(mathif(mathreturnmath;
}else{
returnchinese;
}
}else{
if(englishreturnenglish;
}
else{
returnmath;
}
}
}
}
类StudentGuanli
packagetest;
importjava.util.Scanner;
publicclassStudentGuanli{
staticStudentstudent[]=newStudent[100];
Scannerinput=newScanner(System.in);
privatestaticScannerin2;
//得到当前数组中学生的数量
intstudentNum=this.getStudentNum();
publicintgetStudentNum(){
inti=0;
while(student[i]!
=null){
i++;
}
returni;
}
//添加学生的方法
publicvoidaddStudent(Studenta){
intc=0;
for(inti=0;iif(student[i]==null){
System.out.println("输入学号:
");
a.setStuno(input.nextLine());
System.out.println("输入姓名:
");
a.setName(input.nextLine());
System.out.println("输入语文成绩:
");
a.setchinese(input.nextFloat());
System.out.println("输入数学成绩:
");
a.setMath(input.nextFloat());
System.out.println("输入英语成绩:
");
a.setEnglish(input.nextFloat());
for(intj=0;jif(student[j]!
=null)
c++;
}
student[c]=a;
System.out.println("添加成功!
");
break;
}
}
}
//删除学生的方法
publicvoiddeleteStudent(Stringstuno){
for(inti=0;i<=studentNum;i++){
if(student[i].stuno.equals(stuno)){
System.out.println("删除成功!
");
student[i]=null;
for(intj=i;jstudent[j]=student[j+1];//将后面的值依次向前赋值
}
break;
}
System.out.println("没有此学号的学生!
");
}
}
//查找学生的方法
publicvoidsearchStudent(Stringstuno){
for(inti=0;i<=studentNum;i++){
if(student[i].stuno.equals(stuno)){
System.out.println("查找成功!
");
System.out.println("学号:
"+student[i].stuno+"姓名:
"+student[i].name+
"数学成绩:
"+student[i].math+"英语成绩:
"+student[i].english+"语文成绩:
"
+student[i].chinese);
break;
}else{
System.out.println("没有此学号学生!
请重新查询");
}
}
}
//修改学生的方法
publicvoidalterStudent(Stringstuno,Studenta){
for(inti=0;i<=studentNum;i++){
if(student[i].stuno.equals(stuno)){
System.out.println("修改后学号:
");
a.setStuno(input.nextLine());
System.out.println("修改后姓名:
");
a.setName(input.nextLine());
System.out.println("修改后数学成绩:
");
a.setMath(input.nextFloat());
System.out.println("修改后英语成绩:
");
a.setEnglish(input.nextFloat());
System.out.println("修改后语文成绩:
");
a.setchinese(input.nextFloat());
student[i]=a;
System.out.println("修改成功!
");
break;
}
System.out.println("没有此学号的学生!
");
}
}
//打印学生的方法
publicvoidprintStudent(){
System.out.println(studentNum);
for(inti=0;i<=studentNum;i++){
if(student[i]!
=null){
System.out.println("学号:
"+student[i].stuno+"姓名:
"+student[i].name+
"数学成绩:
"+student[i].math+"英语成绩:
"+student[i].english+"语文成绩"
+student[i].chinese);
}
}
}
//统计学生的方法
publicvoidinfoStudent(){
inti=0;
while(student[i]!
=null){
i++;
}
System.out.println("共用学生"+i+"名");
}
publicstaticvoidmain(String[]args){
//TODO自动生成的方法存根
//菜单:
添加学生、删除学生,查找学生、修改学生、打印学生
//使用数组来实现对多个学生的管理
System.out.println("\n\n\t欢迎使用学生成绩管理系统");
System.out.println("**********************************");
System.out.println("1、添加学生\n2、删除学生\n3、查询学生\n4、修改学生\n5、打印学生\n6、统计学生\n7、退出系统");
booleanflag=true;
while(flag){
Studenta=newStudent();
StudentGuanlid=newStudentGuanli();
in2=newScanner(System.in);
System.out.println("输入你选择的功能:
");
ints=in2.nextInt();
switch(s){
case1:
System.out.println("输入你要添加学生的信息:
");
d.addStudent(a);
break;
case2:
System.out.println("输入你要删除的学生的学号:
");
Scannerst=newScanner(System.in);
Stringn=st.nextLine();
d.deleteStudent(n);
break;
case3:
System.out.println("输入你要查询的学生的学号:
");
Scannerst1=newScanner(System.in);
Stringhao=st1.nextLine();
d.searchStudent(hao);
break;
case4: