1、 学生信息管理系统源代码import java.io.*;class StuInfo public String name;public int number;public String sex;public String age;public String bir;public String email;public String addr;public String tel;public String getName() return name;public void setName(String name) this.name = name;public int getNumber()
2、return number;public void setNumber(int number) this.number = number;public String getSex() return sex;public void setSex(String sex) this.sex = sex;public String getAge() return age;public void setAge(String age) this.age = age;public String getBir() return bir;public void setBir(String bir) this.b
3、ir = bir;public String getEmail() return email;public void setEmail(String email ) this.email = email;public String getAddr() return addr;public void setAddr(String addr) this.addr = addr;public String getTel() return tel;public void setTel(String tel) this.tel = tel;public class Student private sta
4、tic PrintStream out = System.out;private static String filename = “Stu.txt“;private static int total = 0;private static int rt = 0;/recyle lengthprivate StuInfo stuInfos;private StuInfo recycle;BufferedReader buf = new BufferedReader(new InputStreamReader(System.in);/创建缓冲流public Student()stuInfos =
5、new StuInfo11;public void 信息录入()BufferedReader buf = new BufferedReader(new InputStreamReader(System.in);trySystem.out.print(“n 请输入学生信息(以 0 结束)n“);System.out.print(“学号:n“);StuInfo stu = new StuInfo();stu.setNumber(Integer.parseInt(buf.readLine();while(stu.getNumber()!=0) System.out.print(“姓名:nn“);st
6、u.setName(buf.readLine();System.out.print(“性别:nn“);stu.setSex(buf.readLine();System.out.print(“年龄:nn“);stu.setAge (buf.readLine();System.out.print(“生日:nn“);stu.setBir(buf.readLine();System.out.print(“邮箱:nn“);stu.setEmail(buf.readLine();System.out.print(“地址:nn“);stu.setAddr(buf.readLine();System.out.
7、print(“电话:nn“);stu.setTel(buf.readLine();/添加其他输入信息stuInfostotal=stu;total+;stu = new StuInfo();System.out.print(“n 请输入下一个学生信息(以 0 结束)n“);System.out.print(“姓名:n“);stu.setName(buf.readLine();catch(Exception e)out.print(e);public void 保存数据()tryFileWriter fwr=new FileWriter(filename);BufferedWriter fw =
8、 new BufferedWriter(fwr);fw.write(total+“rn“);for(int k=0;ktotal;k+)/保存学生信息fw.write(stuInfosk.getNumber()+“rn“);fw.write(stuInfosk.getName()+“rn“);fw.write(stuInfosk.getSex()+“rn“);fw.write(stuInfosk.getAge()+“rn“);fw.write(stuInfosk.getBir()+“rn“);fw.write(stuInfosk.getEmail()+“rn“);fw.write(stuInf
9、osk.getAddr()+“rn“);fw.write(stuInfosk.getTel()+“rn“);fw.write(rt+“rn“);for(int k=0;krt;k+)/保存回收站信息fw.write(recyclek.getNumber()+“rn“);fw.write(recyclek.getName()+“rn“);fw.write(recyclek.getSex()+“rn“);fw.write(recyclek.getAge()+“rn“);fw.write(recyclek.getBir()+“rn“);fw.write(recyclek.getEmail()+“rn
10、“);fw.write(recyclek.getAddr()+“rn“);fw.write(recyclek.getTel()+“rn“);fw.flush();fw.close();fwr.close();System.out.println(“n 已保存数据! “);catch(Exception e)out.print(e);public void 读取数据()tryFileReader fr = new FileReader(filename);BufferedReader bfr = new BufferedReader(fr);String buff = bfr.readLine(
11、);if(buff != null) total = Integer.parseInt(buff);elsetotal = 0;StuInfo stu;for(int i=0; itotal;i+) stu = new StuInfo();stu.setNumber(Integer.parseInt(bfr.readLine();stu.setName(bfr.readLine();stu.setSex(bfr.readLine();stu.setAge(bfr.readLine();stu.setBir(bfr.readLine();stu.setEmail(bfr.readLine();s
12、tu.setAddr(bfr.readLine();stu.setTel(bfr.readLine();stuInfosi=stu;buff = bfr.readLine();if(buff!= null) rt = Integer.parseInt(buff);elsert = 0;for(int i=0; irt;i+) stu = new StuInfo();stu.setNumber(Integer.parseInt(bfr.readLine();stu.setName(bfr.readLine();stu.setSex(bfr.readLine();stu.setAge(bfr.re
13、adLine();stu.setBir(bfr.readLine();stu.setEmail(bfr.readLine();stu.setAddr(bfr.readLine();stu.setTel(bfr.readLine();/补全recyclei=stu;/ bfr.flush();bfr.close();fr.close();System.out.println(“读取成功“);catch(Exception e)out.print(e);public void 显示学生(StuInfo stus,int length)tryout.println(“-“);for(int i=0;
14、ilength;i+)out.println(“学号:“+stusi.getNumber();out.println(“姓名:“+stusi.getName();out.println(“性别:“+stusi.getSex();out.println(“年龄:“+stusi.getAge();out.println(“生日:“+stusi.getBir();out.println(“邮箱:“+stusi.getEmail();out.println(“地址:“+stusi.getAddr();out.println(“电话:“+stusi.getTel();/输出其他内容.out.printl
15、n(“-“);System.out.println(“请按任意键继续“);buf.read();/catch(Exception e)out.print(e);public void 姓名查询(String name)StuInfo result = new StuInfo11;int r = 0;for(int i=0;itotal;i+)if(stuInfosi.getName().equals(name)resultr=stuInfosi;r+;if(r=0)System.out.print(“查找不到该学生!“);/提示找不到学生return;else显示学生(result, r);p
16、ublic void 学号查询(String number )StuInfo result = new StuInfo11;int r = 0;for(int i=0;itotal;i+)if(Integer.toString(stuInfosi.getNumber().equals(number)resultr=stuInfosi;r+;/补全if(r=0)System.out.print(“查找不到该学生!“);/提示找不到学生else显示学生(result, r);public void 查找菜单()/全字匹配int choice;trydoSystem.out.println(“查找界
17、面“);/System.out.println(“1:按姓名查询 “);System.out.println(“2:按学号查询 “);System.out.println(“0:返回上级 “);BufferedReader buf = new BufferedReader(new InputStreamReader(System.in);choice = Integer.parseInt(buf.readLine();switch(choice)case 1:System.out.println(“请输入姓名“);/获得输入的姓名String name = buf.readLine();姓名查
18、询(name);break;case 2:System.out.println(“请输入学号“);String number = buf.readLine();学号查询(number);/获得输入的学号break;default:System.out.println(“对不起,出现异常!“);/异常:7while(choice!=0);catch(Exception e)out.print(e);public boolean 修改学生(int number) boolean flag = false;tryfor(int i=0;itotal;i+)if(stuInfosi.getNumber
19、()=number) BufferedReader buf = new BufferedReader(new InputStreamReader(System.in);StuInfo stu = new StuInfo();System.out.print(“n 请输入学生信息n“);System.out.print(“姓名:nn“);stu.setName(buf.readLine();System.out.print(“性别:nn“);stu.setSex(buf.readLine();System.out.print(“年龄:nn“);stu.setAge (buf.readLine()
20、;System.out.print(“生日:nn“);stu.setBir(buf.readLine();System.out.print(“邮箱:nn“);stu.setEmail(buf.readLine();System.out.print(“地址:nn“);stu.setAddr(buf.readLine();System.out.print(“电话:nn“);stu.setTel(buf.readLine();stu.setNumber(number);stuInfosi=stu;System.out.print(“修改完成啦!“);/提示修改完成break;catch(Except
21、ion e)out.print(e);return flag;public boolean 删除学生(int number)boolean flag = false;for(int i=0;itotal;i+)if(stuInfosi.getNumber()=number)if(rt=0)recycle = new StuInfo101;recyclert=stuInfosi;for(;itotal-1;i+)stuInfosi=stuInfosi+1;total-;flag=true;break;return flag;public void 删除页面()System.out.print(“
22、删除页面“);/ 请输入要删除的学号tryint choice;BufferedReader buf = new BufferedReader(new InputStreamReader(System.in);System.out.println(“1:学生信息修改 “);System.out.println(“2:学生信息删除 “);System.out.println(“请输入您的选择(1-2)“);/.choice = Integer.parseInt(buf.readLine();switch(choice)case 1:System.out.println(“请输入要修改的学号:“)
23、;choice = Integer.parseInt(buf.readLine();修改学生(choice);break;case 2:System.out.println(“请输入要删除的学号:“);choice = Integer.parseInt(buf.readLine();删除学生(choice);break;/补充/*if(删除学生 (choice)System.out.print(“删除成功!“);/删除成功elseSystem.out.print(“删除失败!“);/删除失败*/catch(Exception e)out.print(e);public void showMen
24、u() tryint choice;doSystem.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(“0:退出系统 “);System.out.println(“请输入
25、您的选择(0-6)“);BufferedReader buf = new BufferedReader(new InputStreamReader(System.in);choice = Integer.parseInt(buf.readLine();switch(choice)case 1:信息录入();/break;case 2:/补全方法调用显示学生(stuInfos, total);break;case 3:查找菜单();break;case 4:删除页面();break;case 5:保存数据();break;case 6:读取数据();break;default:System.out.print(“出现异常!“); /异常:7while(choice!=0);catch(Exception e)System.out.println(e);/ TODO 自动生成的方法存根public static void main(String args) Student student = new Student();student.showMenu();