问题描述
importjava.util.ArrayList;importjava.util.Iterator;importjava.util.Scanner;importjava.io.*;publicclassa5438{publicstaticvoidmain(String[]args)throwsException{while(true){newLogin().log0(args);}}}classLogin{Scannersc=newScanner(System.in);staticArrayList<user>list=newArrayList<user>();staticuseru;publicvoidlog0(String[]args)throwsException{try{FileOutputStreamfo=newFileOutputStream("user.data");ObjectOutputStreamuo=newObjectOutputStream(fo);System.out.println("WelcometoStudnetManagementSystem");System.out.println("=================================================================");System.out.println("现提供一个管理员账号,两个教师管理员账号,两个学生账号进行程序初始运行测试");System.out.println("管理员如需添加教师账号信息或学生账号信息,请登陆到程序管理员界面进行增删查改");System.out.println("=================================================================");useru=newTeacher("admin","123",1);uo.writeObject(u);u=newTeacher("teacher1","333",2);uo.writeObject(u);u=newTeacher("teacher2","369",2);uo.writeObject(u);u=newTeacher("student1","334",3);uo.writeObject(u);u=newTeacher("student2","533",3);uo.writeObject(u);uo.close();fo.close();}catch(IOExceptione){e.printStackTrace();}u=null;try{FileInputStreamfi=newFileInputStream("user.data");ObjectInputStreamsi=newObjectInputStream(fi);while(true){u=(user)si.readObject();System.out.println(u.getNo()+""+u.getPwd());list.add(u);}}catch(EOFExceptione){}Logint=newLogin();t.login();}voidlogin(){System.out.println();System.out.print("请输入卡号:");Stringno=sc.next();System.out.print("请输入密码:");Stringpwd=sc.next();Iterator<user>it=list.iterator();while(it.hasNext()){usertep=it.next();System.out.println(tep.getNo()+""+tep.getPwd());System.out.println();if(tep.getNo().equals(no)&&tep.getPwd().equals(pwd)){inttype=tep.getType();switch(type){case1:newManagement().input1();break;case2:newTeacher().input2();break;case3:break;default:System.exit(type);}u.menu();System.exit(0);}}System.out.println("账号或者密码错误!");}}abstractclassuserimplementsSerializable{privateStringno;privateStringpwd;privateinttype;privateStringtype2;privateStringname;abstractvoidmenu();publicuser(){}publicuser(Stringno,Stringpwd,inttype){this.no=no;this.pwd=pwd;this.type=type;}publicuser(Stringno,Stringpwd,inttype,Stringtype2,Stringname){this.no=no;this.pwd=pwd;this.type=type;this.type2=type2;this.name=name;}publicStringgetName(){returnname;}publicvoidsetName(){this.name=name;}publicStringgetNo(){returnno;}publicvoidsetNo(Stringno){this.no=no;}publicStringgetPwd(){returnpwd;}publicvoidsetPwd(Stringpwd){this.pwd=pwd;}publicintgetType(){returntype;}publicvoidsetType(inttype){this.type=type;}publicStringgetType2(){returntype2;}publicvoidsetType2(Stringtype2){this.type2=type2;}}classTeacherextendsuser{publicTeacher(){super();}publicTeacher(Stringno,Stringpwd,inttype){super(no,pwd,type);}publicTeacher(Stringno,Stringpwd,inttype,Stringtype2,Stringname){super(no,pwd,type,type2,name);}voidmenu(){demo();System.out.println("teacher:");}voiddemo(){System.out.println("teachermethod");}voidinput2(){while(true){Scannerin1=newScanner(System.in);System.out.println("欢迎来到教师添加成绩界面");System.out.println("====================");System.out.println("请选择以下功能:");System.out.println("1.录入平时成绩");System.out.println("2.录入期末成绩");System.out.println("3.察看专业排名");System.out.println("4.察看班级排名");System.out.println("5.察看单科课程信息");System.out.println("6.返回上一层");System.out.println("7.退出");intsel2=in1.nextInt();switch(sel2){case1://Add_Temp_Mark();break;case2:break;case3:break;case4:break;case5:break;case7:System.exit(sel2);case6:newLogin().login();default:System.out.println("输入有误,请重新输入");}}}}classManagementextendsuser{staticArrayList<user>list=newArrayList<user>();Scannerin1=newScanner(System.in);staticuseru;voidinput1(){while(true){System.out.println("管理员管理界面");System.out.println("============");System.out.println("请选择:");System.out.println("1.管理学生信息");System.out.println("2.管理老师信息");System.out.println("3.管理课程信息");System.out.println("4.退出");System.out.println("5.返回上一层");System.out.println("============");intsel=in1.nextInt();switch(sel){case1:input1_1();break;case2:input1_2();break;case3:input1_3();break;case4:System.exit(sel);break;case5:newLogin().login();break;default:System.out.println("输入有误,请确认后重新输入");}}}voidinput1_1(){System.out.println("1.添加学生信息");System.out.println("2.删除学生信息");System.out.println("3.修改学生信息");System.out.println("4.查询学生信息");System.out.println("5.返回上一层");intsel=in1.nextInt();switch(sel){case1:break;case2:break;case3:break;case4:break;case5:break;default:System.out.println("输入有误,请重新输入");}}voidinput1_2(){System.out.println("1.添加老师信息");System.out.println("2.删除老师信息");System.out.println("3.修改老师信息");System.out.println("4.查询老师信息");System.out.println("5.返回上一层");intsel=in1.nextInt();switch(sel){case1:try{add_tea_mes();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}break;case2:break;case3:break;case4:break;case5:break;default:System.out.println("输入有误,请重新输入");}}voidinput1_3(){System.out.println("1.添加课程信息");System.out.println("2.修改课程信息");System.out.println("3.删除课程信息");System.out.println("4.返回上一层");intsel=in1.nextInt();switch(sel){case1:break;case2:break;case3:break;case4:break;case5:break;default:System.out.println("输入有误,请重新输入");}}voidadd_stu_mes(){}voidadd_tea_mes()throwsIOException{FileOutputStreamfo=newFileOutputStream("user.data",true);ObjectOutputStreamuo=newObjectOutputStream(fo);System.out.println();System.out.println("姓名:");Stringname=in1.next();System.out.println("帐号:");Stringid=in1.next();System.out.println("密码:");Stringpwd=in1.next();System.out.println("类型:");inttype=in1.nextInt();System.out.println("任课:");Stringtype2=in1.next();u=newTeacher(id,pwd,type,type2,name);FileInputStreamfi=newFileInputStream("user.data");ObjectInputStreamsi=newObjectInputStream(fi);while(true){try{u=(user)si.readObject();}catch(ClassNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}System.out.println(u.getNo()+""+u.getPwd());list.add(u);}}@Overridevoidmenu(){//TODOAuto-generatedmethodstub}}classStudentextendsuser{BufferedReaderin=newBufferedReader(newInputStreamReader(System.in));Scannerin3=newScanner(System.in);@Overridevoidmenu(){//TODOAuto-generatedmethodstub}}classCourse{}
解决方案
解决方案二:
这是错误代码:管理员管理界面============请选择:1.管理学生信息2.管理老师信息3.管理课程信息4.退出5.返回上一层============java.io.StreamCorruptedExceptionatjava.io.ObjectInputStream.readObject0(UnknownSource)atjava.io.ObjectInputStream.readObject(UnknownSource)atManagement.add_tea_mes(a5438.java:342)atManagement.input1_2(a5438.java:277)atManagement.input1(a5438.java:226)atLogin.login(a5438.java:76)atLogin.log0(a5438.java:56)ata5438.main(a5438.java:10)31.添加课程信息2.修改课程信息3.删除课程信息4.返回上一层