学生信息管理系统(运用集合、且存储本地磁盘)

上传人:第*** 文档编号:34063147 上传时间:2018-02-20 格式:DOCX 页数:10 大小:38.69KB
返回 下载 相关 举报
学生信息管理系统(运用集合、且存储本地磁盘)_第1页
第1页 / 共10页
学生信息管理系统(运用集合、且存储本地磁盘)_第2页
第2页 / 共10页
学生信息管理系统(运用集合、且存储本地磁盘)_第3页
第3页 / 共10页
学生信息管理系统(运用集合、且存储本地磁盘)_第4页
第4页 / 共10页
学生信息管理系统(运用集合、且存储本地磁盘)_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《学生信息管理系统(运用集合、且存储本地磁盘)》由会员分享,可在线阅读,更多相关《学生信息管理系统(运用集合、且存储本地磁盘)(10页珍藏版)》请在金锄头文库上搜索。

1、学生信息管理系统-基于 io 流,集合,面向对象知识部分运行图:完整代码如下,仅供学习参考:package com.gaobo.day13,homework;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.IOException;import java.io.ObjectInputStream;import java.io.

2、ObjectOutputStream;import java.io.Serializable;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Scanner;public class IoObjOutputListStuMess static ArrayList message = new ArrayList();public static void main(String args) initDate();/进入系统时读取之前所存储的数据到缓冲区Scanne

3、r input = new Scanner(System.in);dis();while(true)String in = input.next();switch(in)case 1:addStuMess(); break;case 2:showStuMess();break;case 3:changStudentMess();break;case 4:delStudentMess();break;case 5:findStuMess();break;case 6:savaDate(); System.out.println(退出程序成功!);System.exit(0);default :S

4、ystem.out.println(输入错误,请选择 16!);dis();public static void addStuMess()String flag =y ;do boolean isInt=true,isYN = true;Scanner input = new Scanner(System.in);Student stu = new Student(null, null, 0, null);/随意设定初始值,不影响程序,只为了创建对象,类型对应即可System.out.println(请输入学生的学号);String in = input.next();stu.setNo(in

5、);for(Student hadStu:message)if(hadStu.getNo().equals(in)System.out.println(已存在该学生,不能重复添加);dis();return;System.out.println(请输入学生的姓名);stu.setName(input.next();System.out.println(请输入学生的年龄);/对于年龄为整数的异常处理while(isInt)Scanner intInput = new Scanner(System.in);try isInt = false;int intAge = intInput.nextIn

6、t();if(intAge150|intAge it = message.iterator(); /构建迭代器while(it.hasNext()Student stuMess = it.next();if(stuMess.getNo().equals(in)aa:while(true)boolean isInt = true;System.out.println(请选择你要修改的信息:);System.out.println(1、学号 2、姓名 3、年龄 4、性别 5、 【 保存】);String type = input.next();/修改内容选项switch(type)case 1:b

7、oolean flag =true;System.out.println(学号修改为:);/修改学号时,原则是不能出现相同的学号while(flag)String isHad = input.next();for(Student hadStu:message)if(hadStu.getNo().equals(isHad)System.out.println(已存在该学生,不能重复添加);flag = true;break;elseflag = false;if(flag = false)stuMess.setNo(isHad);System.out.println(学号修改成功.); brea

8、k;case 2:System.out.println(姓名修改为:);stuMess.setName(input.next();System.out.println(姓名修改成功.);break;case 3:System.out.println(年龄修改为:);/对于年龄为整数的异常处理while(isInt)Scanner intInput = new Scanner(System.in);try isInt = false;int intAge = intInput.nextInt();if(intAge150|intAge it = message.iterator(); /构建迭代

9、器while(it.hasNext()Student stuMess = it.next();if(stuMess.getNo().equals(in)message.remove(stuMess);System.out.println(删除该学生信息成功.);dis();return;System.out.println(对不起,没有找到该学生信息);dis();public static void findStuMess()if(message.size()=0)System.out.println(学生信息库为空,请先添加学生信息);dis();return;System.out.pri

10、ntln(请输入您要查找的学生学号);Scanner input = new Scanner(System.in);String in = input.next();Iterator it = message.iterator(); /构建迭代器while(it.hasNext()Student stuMess = it.next();if(stuMess.getNo().equals(in)System.out.println(该学生信息如下:);System.out.println(学号t 姓名t 年龄t 性别);System.out.println(stuMess.getNo()+t+s

11、tuMess.getName()+t+stuMess.getAge()+t+stuMess.getGender();dis();return;System.out.println(删除失败,没有该学生信息.);dis();public static void savaDate()try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(IoObjOutputListStuMess.dat);/file 路径可根据实际需要来改)oos.writeObject(message);/对象应用的序列化:直接将 S

12、tudent 对象存入message 集合中 catch (FileNotFoundException e) / e.printStackTrace();dis(); catch (IOException e) e.printStackTrace();public static void initDate()try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(IoObjOutputListStuMess.dat);)try message = (ArrayList)ois.readObject(); ca

13、tch (ClassNotFoundException e) catch (FileNotFoundException e) / e.printStackTrace();System.out.println(-首次加载,请添加学生信息!-); catch (IOException e) / e.printStackTrace();static void dis()System.out.println(*欢迎使用学生信息管理系统 *);System.out.println(| 1、增加一个学生 |);System.out.println(| 2、显示所有学生 |);System.out.prin

14、tln(| 3、修改学生信息 |);System.out.println(| 4、删除学生信息 |);System.out.println(| 5、查找学生 |);System.out.println(| 6、退出程序 |);System.out.println(| (请选择 16) |);System.out.println(*); class Student implements Serializable/实现 Serializable 接口,该类就是可序列化的private String no,name,gender;private int age;public String getNo() return no;public void setNo(String no) this.no = no;public String getName() return name;public void setName(String name) this.name = name;public int getAge()

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号