学生管理系统的设计与实现 学生管理系统设计要求

龙途教育 1次浏览

摘要:您好,今天欣欣来为大家解答以上的问题。学生管理系统的设计与实现相信很多小伙伴还不知道,现在让我们一起来看看

您好,今天欣欣来为大家解答以上的问题。学生管理系统的设计与实现相信很多小伙伴还不知道,现在让我们一起来看看吧!

1、packaged;importja.io.;importja.util.;publicclassTreemap{staticTreeMaptm=newTreeMap();//实例化一个树对象staticStudents;//声明一个静态变量Spublicstaticvoidmain(Stringargs[]){try{fis=new("students.txt");//实例化一个对象并且读取students.txt文件ois=new(fis);while((s=(Student)(ois.readObject()))!=null){tm.put(s.stunum,s);}ois.close();}catch(IOExceptionioe){}catch(c){}try{while(true){System.out.println("[0]主菜单[1]查找[2]输入[3]删除[4]全部列出[5]退出");//显示菜单System.out.print("请选择作:");is=new(System.in);br=new(is);Stringch=br.readLine();intc=Integer.parseInt(ch);switch(c){case0:break;case1:search();break;case2:input();break;case3:delete();break;case4:listAll();break;case5:tm.clear();System.exit(0);break;default:System.out.println("输入有误!");}}}catch(IOExceptione){}catch(e){System.out.println("输入有误!");}}staticvoidlistAll(){tm.clear();try{fis=new("students.dat");ois=new(fis);while((s=(Student)(ois.readObject()))!=null){tm.put(s.stunum,s);System.out.println(s.stunum""s.stuname);}ois.close();}catch(IOExceptionioe){}catch(c){}}staticvoidinput(){Stringstr1=null,str2=null;try{InputStreamReaderis=newInputStreamReader(System.in);BufferedReaderbr=newBufferedReader(is);System.out.print("请输入学号:");str1=br.readLine();System.out.print("请输入姓名:");str2=br.readLine();}catch(IOExceptione){System.out.println(e);}s=newStudent(str1,str2);tm.put(s.stunum,s);//写文件intn=1;try{FileOutputStreamfos=newFileOutputStream("students.dat");ObjectOutputStreamoos=newObjectOutputStream(fos);for(Iteratorit=tm.values().iterator();it.hasNext();){s=(Student)it.next();oos.writeObject(s);}oos.close();}catch(IOExceptione){System.out.println(e);}}staticvoidsearch(){Stringkey=null;try{InputStreamReaderis=newInputStreamReader(System.in);BufferedReaderbr=newBufferedReader(is);System.out.print("请输入一个学号:");key=br.readLine();}catch(IOExceptione){System.out.println(e);}if(tm.containsKey(key)){s=(Student)tm.get(key);System.out.println(s.stunum""s.stuname);}elseSystem.out.println("没有");}staticvoiddelete(){Stringkey=null;try{InputStreamReaderis=newInputStreamReader(System.in);BufferedReaderbr=newBufferedReader(is);System.out.print("请输入学号:");key=br.readLine();}catch(IOExceptione){}if(tm.remove(key).equals(null)){System.out.println("没有");}try{FileOutputStreamfos=newFileOutputStream("students.dat");ObjectOutputStreamoos=newObjectOutputStream(fos);for(Iteratorit=tm.values().iterator();it.hasNext();){s=(Student)it.next();oos.writeObject(s);}oos.close();}catch(IOExceptione){System.out.println(e);}}}classStudentimplementsSerializable{Stringstunum;Stringstuname;publicStudent(Stringstunum,Stringstuname){this.stunum=stunum;this.stuname=stuname;}}。

本文到这结束,希望上面文章对大家有所帮助。

版权声明:本文发布于龙途教育 图片、内容均来源于互联网 如有侵权联系836084111@qq.com删除
随机内容