用JAVA编写的学生管理系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

importjava.io.InputStreamReader;importjava.util.Scanner;/**@author*@since2013-07-28*/classstudent{//定义一个学生类privatestaticfinalintSUBJECT_NUM=0;Stringname=;Stringid=;intrecord[]=newint[3];inttotal=0;publicstudent(Stringname,Stringid,int[]record,inttotal){super();this.name=name;this.id=id;this.record=record;this.total=total;}publicStringgetStudentId(){//定义get()和set()方法returnid;}publicvoidsetStudentId(StringstudentId){this.id=studentId;}publicStringgetStudentName(){returnname;}publicvoidsetStudentName(StringstudentName){this.name=studentName;}publicint[]getGrades(){returnrecord;}publicvoidsetGrades(int[]grades){this.record=grades;}publicintgetTotal(){returntotal;}publicvoidsetTotal(inttotal){this.total=total;}publicintgetSUBJECT_NUM(){returnSUBJECT_NUM;}}publicclassStudentsystem{privatestaticintcurrentNum=0;privatefinalstaticintTOTAL=60;publicstaticScannerscanner=newScanner(newInputStreamReader(System.in));privatestaticstudent[]student=newstudent[TOTAL];publicstaticvoidmain(String[]args){ScanneruserInPut=newScanner(System.in);booleanflag=true;Studentsystemstus=newStudentsystem();//建立菜单选择系统while(true){System.out.println(----------------------欢迎进入菜单选择系统------------------------);System.out.println(1.添加学生2.删除学生3.比较两个人的总成绩4.查询学生信息);System.out.println(5.排序6.按总成绩过滤7.修改学生信息:8.显示学生信息:);intEnternumber;Enternumber=userInPut.nextInt();switch(Enternumber){case1://添加学生for(inti=0;i3;i++){System.out.println(请输入学生信息:姓名,学号,数学,英语,JAVA,);stus.addInformation();}break;case2://删除学生System.out.println(输入要删除学生的学号:);Studentsystem.deleteInformation();break;case3://比较两个人的总成绩System.out.println(请输入要比较的两个学生的学号:);Studentsystem.compareInformation();break;case4://查询学生信息System.out.println(请输入要查询的学生学号:);Studentsystem.selectInformation();break;case5://排序Studentsystem.sortInformation();break;case6://按总成绩过滤System.out.println(请输入要过滤的分数:);Studentsystem.guolvInformation();break;case7://修改学生信息System.out.println(请输入要修改的姓名:);Studentsystem.changeInformation();break;case8://显示学生信息Studentsystem.showInformation();break;case9:return;default:break;}}}voidaddInformation(){//添加学生Stringname=;Stringid=;intrecord[]=newint[3];inttotal=0;name=scanner.next();id=scanner.next();for(inti=0;irecord.length;i++){//计算总分record[i]=scanner.nextInt();total=total+record[i];}student[currentNum]=newstudent(name,id,record,total);currentNum++;}publicstaticvoiddeleteInformation(){//删除学生Stringdelid=scanner.next().trim();inttemp=0,num;for(num=0;numcurrentNum;num++){if(student[num].getStudentId().equals(delid)){//找到要删除学生的idbreak;}}if(num==currentNum){System.out.println(没有找到指定的学生信息!);}else{for(inti=num;icurrentNum;i++){student[i]=student[i+1];}student[num]=null;currentNum--;System.out.println(学生信息删除成功!);}}publicstaticbooleancompareInformation(){//比较两人的成绩StringstuId1=scanner.next();StringstuId2=scanner.next();intindex1=0;intindex2=0;intnum;booleanflag1=true,flag2=true;//判断第一个学号是否存在for(num=0;numcurrentNum;num++){if(stuId1.equals(student[num].getStudentId())){index1=num;break;}}if(num==currentNum){System.out.println(没有找到指定学号的学生信息!);flag1=false;}//判断输入的第二个学号是否存在for(num=0;numcurrentNum;num++){if(stuId2.equals(student[num].getStudentId())){index2=num;break;}}if(num==currentNum){flag2=false;}if(!flag2||!flag1){//若输入的学号有不存在,打印提示信息,结束比较System.out.println(没有找到指定的学生信息!);returnfalse;}else{//若输入的学号都存在,进行成绩比较,输出结果System.out.println(student[index1].getStudentName()+的数学、英语、java、总分:+student[index1].getGrades()[0]++student[index1].getGrades()[1]++student[index1].getGrades()[2]++student[index1].getTotal()+\r\n+student[index2].getStudentName()+的数学、英语、java、总分:+student[index2].getStudentName()++student[index2].getGrades()[0]++student[index2].getGrades()[1]++student[index2].getGrades()[2]++student[index2].getTotal()+\r\n);if(student[index1].getTotal()student[index2].getTotal()){System.out.println(student[index1].getStudentName()+同学总分比+student[index2].getStudentName()+多+(student[index1].getTotal()-student[index2].getTotal())+分);}elseif(student[index1].getTotal()student[index2].getTotal()){System.out.println(student[index2].getStudentName()+同学总分比+student[index1].getStudentName()+多+(student[index2].getTotal()-student[index1].getTotal())+分);}else{System.out.println(student[index1].getStudentName()+和+student[index2].getStudentName()+总分相同);}returntrue;}}publicstaticvoidselectInformation(){//查询学生的信息intnum;StringstuId=scanner.next();for(num=0;numcurrentNum;num++){if(student[num].getStudentId().equals(stuId)){//找到要查寻得idbreak;}}if(num==currentNum){System.out.println(没有找到指定的学生信息!);}else{System.out.println(要查询的学生信息为:+姓名:+student[num].getStudentName()++学号:+student[num].getStudentId()++数学成绩:+student[num].getGrades()[0]++.英语成绩:+student[num].getGrades()[1]++JAVA:+student[num].getGrades()[2]++总分:+student[num].getTotal()+);}}publicstaticvoidsortInformation(){//按总成绩排序intpoint=0;while(student[point]!=null){point++;}intlength=point;intgradeTemp[]=newint[length];StringnameTemp[]=newString[length];//取出已经存在的学生的相关信息到临时数组中存储for(inti=0;ilength;i++){gradeTemp[i]=student[i].getTotal();nameTemp[i]=student[i].getStudentName();}//利用选择

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功