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; p
2、ublic int getNumber() 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 v
3、oid setBir(String bir) this.bir = 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 = t
4、el; public class Student private static PrintStream out = System.out; private static String filename = Stu.txt; private static int total = 0; private static int rt = 0;/recyle length private StuInfo stuInfos; private StuInfo recycle; BufferedReader buf = new BufferedReader(new InputStreamReader(Syst
5、em.in);/创建缓冲流 public Student() stuInfos = new StuInfo11; public void 信息录入() BufferedReader buf = new BufferedReader(new InputStreamReader(System.in); try System.out.print(n请输入学生信息(以0结束)n); System.out.print(学号:n); StuInfo stu = new StuInfo(); stu.setNumber(Integer.parseInt(buf.readLine(); while(stu.g
6、etNumber()!=0) System.out.print(姓名:nn); stu.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(地址:n
7、n); stu.setAddr(buf.readLine(); System.out.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 保存数据() try FileWriter f
8、wr=new FileWriter(filename); BufferedWriter fw = 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.writ
9、e(stuInfosk.getEmail()+rn); fw.write(stuInfosk.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()+r
10、n); fw.write(recyclek.getEmail()+rn); 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 读取数据() try FileReader fr = new FileReader(filename); BufferedReader bfr = new Buffered
11、Reader(fr); String buff = bfr.readLine(); if(buff != null) total = Integer.parseInt(buff); else total = 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.se
12、tBir(bfr.readLine(); stu.setEmail(bfr.readLine(); stu.setAddr(bfr.readLine(); stu.setTel(bfr.readLine(); stuInfosi=stu; buff = bfr.readLine(); if(buff!= null) rt = Integer.parseInt(buff); else rt = 0; for(int i=0; irt;i+) stu = new StuInfo(); stu.setNumber(Integer.parseInt(bfr.readLine(); stu.setNam
13、e(bfr.readLine(); stu.setSex(bfr.readLine(); stu.setAge(bfr.readLine(); 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);
14、public void 显示学生(StuInfo stus,int length) try out.println(-); for(int i=0;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(地址:+
15、stusi.getAddr(); out.println(电话:+stusi.getTel(); /输出其他内容. out.println(-); 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;
16、r+; if(r=0) System.out.print(查找不到该学生!); /提示找不到学生 return; else 显示学生(result, r); public 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(查找不到该学生!);/提示找
17、不到学生 else 显示学生(result, r); public void 查找菜单()/全字匹配 int choice; try do System.out.println(查找界面);/ 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(); s
18、witch(choice) case 1: System.out.println(请输入姓名);/获得输入的姓名 String name = buf.readLine(); 姓名查询(name); break; case 2: System.out.println(请输入学号); String number = buf.readLine(); 学号查询(number);/获得输入的学号 break; default: System.out.println(对不起,出现异常!); /异常:7 while(choice!=0); catch(Exception e) out.print(e); p
19、ublic boolean 修改学生(int number) boolean flag = false; try for(int i=0;itotal;i+) if(stuInfosi.getNumber()=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(); Sy
20、stem.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.print(电话:nn); stu.setTel(bu
21、f.readLine(); stu.setNumber(number); stuInfosi=stu; System.out.print(修改完成啦!);/提示修改完成 break; catch(Exception 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=stuInfo
22、si; for(;itotal-1;i+) stuInfosi=stuInfosi+1; total-; flag=true; break; return flag; public void 删除页面() System.out.print(删除页面);/请输入要删除的学号 try int choice; BufferedReader buf = new BufferedReader(new InputStreamReader(System.in); System.out.println(1:学生信息修改); System.out.println(2:学生信息删除); System.out.pr
23、intln(请输入您的选择(1-2)); /. choice = Integer.parseInt(buf.readLine(); switch(choice) case 1: System.out.println(请输入要修改的学号:); choice = Integer.parseInt(buf.readLine(); 修改学生(choice); break; case 2: System.out.println(请输入要删除的学号:); choice = Integer.parseInt(buf.readLine(); 删除学生(choice); break; /补充 /*if(删除学生
24、(choice) System.out.print(删除成功!);/删除成功 else System.out.print(删除失败!);/删除失败 */ catch(Exception e) out.print(e); public void showMenu() try int choice; do 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(0:退出系统); System.out.println(请输入您的选择(0-6)); BufferedReader buf = new BufferedReader(new InputStreamReader(System.in); choice = Integer.parseInt(buf.readLine(); switch(choice)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1