下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
学生成绩管理系统importjava.util.*;importjava.io.*;classStudentimplementsSerializable{ Stringname; longno; privateString[]course={"os","java","math"}; double[]cscore={0,0,0}; publicStudent(Stringname,longno,doublea,doubleb,doublec){ =name; this.no=no; this.cscore[0]=a; this.cscore[1]=b; this.cscore[2]=c; } @OverridepublicStringtoString(){ return+""+this.no+""+this.course[0]+":"+this.cscore[0] +""+this.course[1]+":"+this.cscore[1]+""+this.course[2]+":"+this.cscore[2]; }}publicclassObject{ privatestaticScannerscanner=newScanner(System.in); publicStudent[]read()throwsException{ ObjectInputStreamobjIn=newObjectInputStream(newFileInputStream("stus.data")); intnum=objIn.readInt(); Student[]stus=newStudent[num]; for(inti=0;i<num;i++){ stus[i]=(Student)objIn.readObject(); } objIn.close(); returnstus; } publicvoidadd(Student[]stus)throwsException{ Student[]s=newStudent[stus.length+1]; for(inti=0;i<s.length-1;i++){s[i]=stus[i];} System.out.print("请输入要添加的学生信息:\n"+"姓名:");Stringname=scanner.next(); System.out.print("学号:");longno=scanner.nextInt(); System.out.print("os成绩:");doublecscore0=scanner.nextDouble(); System.out.print("java成绩:");doublecscore1=scanner.nextDouble(); System.out.print("math成绩:");doublecscore2=scanner.nextDouble(); s[s.length-1]=newStudent(name,no,cscore0,cscore1,cscore2);save(s); System.out.println("添加成功!"); } publicvoiddispAll(Student[]stus){ System.out.println("现有Student信息为:"); for(Studentstu:stus){ System.out.println(stu); } } publicvoidsave(Student[]stus)throwsException{ ObjectOutputStreamobjOut=newObjectOutputStream(newFileOutputStream("stus.data")); objOut.writeInt(stus.length); for(Studentstu:stus){ objOut.writeObject(stu); } objOut.close(); } publicvoidfindById(Student[]stus){ intno=0,i=0; System.out.print("请输入学号:");no=scanner.nextInt(); for(i=0;i<stus.length;i++){ if(stus[i].no==no){System.out.println(stus[i]);break;} if(stus[i].no!=no&&i==stus.length-1){System.out.println("无该生信息!");} } } publicvoidfindByName(Student[]stus){ Stringname=""; System.out.print("请输入姓名:");name=scanner.next(); for(inti=0;i<stus.length;i++){ if(name.equalsIgnoreCase(stus[i].name)==true){System.out.println(stus[i]);break;} if(name.equalsIgnoreCase(stus[i].name)==false&&i==stus.length-1){System.out.println("无该生信息!");} } } publicvoiddelById(Student[]stus)throwsException{ intno=0,i=0; System.out.print("请输入学号:");no=scanner.nextInt(); for(i=0;i<stus.length;i++){ if(stus[i].no==no){System.out.println(stus[i]);stus[i]=null;save(stus);System.out.println("删除成功!");break;} if(stus[i].no!=no&&i==stus.length-1){System.out.println("无该生信息!");} } } publicstaticvoidmain(String[]args)throwsException{ Objectdemo=newObject(); Student[]stus={newStudent("zhang",1,90,90,98),newStudent("wang",2,80,80,89),newStudent("li",3,70,70,79)}; System.out.print("请输入操作的编号:");System.out.print("\n"); intchoice=0; do{ System.out.println("1添加2显示所有学生信息3按学号查找4按姓名查找5按学号删除6保存0退出"); choice=scanner.nextInt(); switch(choice){ case1:demo.add(demo.read());break; case2:demo.dispAll(demo.read());break; case3:demo.findById(demo.read());break; case4:demo.findByName(demo.read());break;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年单位食堂端午节活动方案及流程
- 2026年基金销售业绩预测分析报告
- 2026年幼儿进餐安全问题分析报告
- 2026年残疾人服务社会活动方案设计
- 2026年安全审计问题分析报告
- 2026年农村小学实验教学实践研究现状
- 2026年博物馆展览设计流程
- 2026年医生发展趋势职业现状调查
- 2026年保险咨询服务合同(甲乙双方)三篇
- 城北水产交易中心项目水土保持方案报告表
- 2026广东广州花都城投西城经济开发有限公司第二次招聘工作人员2人笔试历年参考题库附带答案详解
- 《无人机系统概论》期末考试试卷及答案
- 2026年中国石油大学(华东)综合评价《面试》模拟试题及参考答案
- 2026年重庆市中考物理试卷(含答案及解析 )
- 2025~2026学年湖北省武汉市Joinin外研剑桥英语第一学期五年级期末英语试卷
- 2026山东济南南美城乡发展有限公司及其权属子公司招聘7人笔试参考题库及答案详解
- 【七下历史】期末集训01 选择题100题(原卷版)
- 2026年高考全国II卷地理真题试卷(含答案)
- 2026年云南校长职级测试卷含答案详解【典型题】
- 幼儿园中班音乐活动《小老鼠和泡泡糖》课件
- 2023年编辑清单大师8江苏版软件操作手册
评论
0/150
提交评论