//学生管理系统,利用IO实现
import java.util.Arrays;public class Student {private String name;private String id;private String gender;private int age;private double weight;private double hight;private String[] hobby;public Student() {}public Student(String name, String id,String gender, int age, double weight, double hight, String[] hobby) {this.name = name;this.id = id;this.gender = gender;this.age = age;this.weight = weight;this.hight = hight;this.hobby = hobby;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getGender() {return gender;}public void setGender(String gender) {this.gender = gender;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public double getWeight() {return weight;}public void setWeight(double weight) {this.weight = weight;}public double getHight() {return hight;}public void setHight(double hight) {this.hight = hight;}public String[] getHobby() {return hobby;}public void setHobby(String[] hobby) {this.hobby = hobby;}public String getId() {return id;}public void setId(String id) {this.id = id;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", id='" + id + '\'' +", gender='" + gender + '\'' +", age=" + age +", weight=" + weight +", hight=" + hight +", hobby=" + Arrays.toString(hobby) +'}';}
}

student类对象

下面利用了IO流来实现导入student.txt文件里面的信息

student.txt的内容

李响 2109124001 男 19 200.0 185.0 踢足球,玩手机
李佳豪 2109124002 男 18 178.0 120.0 打游戏,写代码
李佳豪 2109124003 男 20 183.0 150.0 写代码,弹吉他,旅游,拍风景
黄彦鑫 2109124004 男 21 120.0 168.0 刷抖音,旅游,爬山
常妍雨 2109124005 女 19 110.0 168.0 绝地求生,追剧,写代码
郝少杰 2109214007 男 19 120.0 178.0 打游戏,刷抖音,学习
王佳和 2109124012 男 20 200.0 185.0 学习,开车
吕佳俊 2109124018 男 19 100.0 180.0 学习,数学,C++
赵凯悦 2109124022 男 19 160.0 178.0 算法,java,听歌
郑梓桐 2109124027 男 19 160.0 180.0 java,打篮球
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;/*** 利用字符缓冲输出输入流对象实现* IO流将StudentInfo文件中的数据导出来,然后更改,继续写入文件*/public class Arrays {//主函数public static void main(String[] args) throws Exception{Scanner sc = new Scanner(System.in);ArrayList<Student> student = read();pro();System.out.print("请输入功能数字:");int num = sc.nextInt();while (num!=0) {switch (num) {case 0:num=0;break;case 1:student.add(wir());break;case 2:select(student);break;case 3:delete(student);break;case 4:Update(student);break;case 5:show();break;}System.out.print("请再次输入数字:");pro();num=sc.nextInt();}}//更新修改学生信息public static void Update(ArrayList<Student> s) throws Exception {System.out.print("请输入需要修改人的学号:");Scanner sc = new Scanner(System.in);String id = sc.next();for (Student student : s) {if(student.getId().equals(id)){pro2();System.out.print("请输入需要修改的项目的序号:");int num = sc.nextInt();while (num!=0){switch (num){case 0:break;case 1:UpdateName(student);WriteInTxt(s);break;case 2:UpdateId(student);WriteInTxt(s);break;case 3:UpdateGenderStudent(student);WriteInTxt(s);break;case 4:UpdateAge(student);WriteInTxt(s);break;case 5:UpdateWeight(student);WriteInTxt(s);break;case 6:UpdateHight(student);WriteInTxt(s);break;case 7:UpdateHobby(student);WriteInTxt(s);break;}System.out.println();pro2();System.out.print("请输入需要修改的项目的序号:");num= sc.nextInt();}}}}//更新列表消息public static void pro2(){System.out.println("功能");System.out.println("0,退出");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("7,爱好");}//更新爱好public static Student UpdateHobby(Student s){Scanner sc = new Scanner(System.in);System.out.print("请输入新的爱好:");String str = sc.next();String[] split = str.split(",");s.setHobby(split);return s;}//更新身高public static Student UpdateHight(Student s){Scanner sc = new Scanner(System.in);System.out.print("请输入新的身高:");s.setHight(sc.nextDouble());return s;}//更新体重public static Student UpdateWeight(Student s){Scanner sc = new Scanner(System.in);System.out.print("请输入新的体重:");s.setWeight(sc.nextDouble());return s;}//更新年龄public static Student UpdateAge(Student s){Scanner sc = new Scanner(System.in);System.out.print("请输入新的年龄:");s.setAge(sc.nextInt());return s;}//更新性别public static Student UpdateGenderStudent(Student s){Scanner sc = new Scanner(System.in);System.out.print("请输入新的性别:");s.setGender(sc.next());return s;}//更新IDpublic static Student UpdateId(Student s){Scanner sc = new Scanner(System.in);System.out.print("请输入新的学号:");s.setId(sc.next());return s;}//更新名字public static Student UpdateName(Student s){Scanner sc = new Scanner(System.in);System.out.print("请输入新的名字:");s.setName(sc.next());return s;}//写入文件public static void WriteInTxt(ArrayList<Student> s) throws Exception{BufferedWriter bw = new BufferedWriter(new FileWriter("StudentInfo.txt"));for (Student student : s) {String a = null;StringBuffer b = new StringBuffer();for(int i=0;i<student.getHobby().length;i++){b.append(student.getHobby()[i]);if(i!= student.getHobby().length-1){b.append(",");}}bw.write(student.getName()+" "+student.getId()+" "+student.getGender()+" "+student.getAge()+" "+student.getWeight()+" "+student.getHight()+" "+b.toString());bw.newLine();bw.flush();}}//功能函数public static void pro(){System.out.println("功能");System.out.println("0,退出");System.out.println("1,添加学生");System.out.println("2,查找学生");System.out.println("3,删除学生");System.out.println("4,更改学生信息");System.out.println("5,打印全部学生信息");}//展示文件信息public static void show() throws Exception{BufferedReader br = new BufferedReader(new FileReader("StudentInfo.txt"));String line = null;while((line=br.readLine())!=null){System.out.println(line);}}//删除public static void delete(ArrayList<Student> s) throws Exception{Scanner sc = new Scanner(System.in);BufferedWriter bw = new BufferedWriter(new FileWriter("StudentInfo.txt"));System.out.println("请输入需要删除的人的姓名");String name = sc.next();for(int i =0 ;i<s.size();i++){if(s.get(i).getName().equals(name)){s.remove(i);System.out.println("删除成功");}}for (Student student : s) {String a = null;StringBuffer b = new StringBuffer();for(int i=0;i<student.getHobby().length;i++){b.append(student.getHobby()[i]);if(i!= student.getHobby().length-1){b.append(",");}}bw.write(student.getName()+" "+student.getId()+" "+student.getGender()+" "+student.getAge()+" "+student.getWeight()+" "+student.getHight()+" "+b.toString());bw.newLine();bw.flush();}}//查找public static void select(ArrayList<Student> s){Scanner sc = new Scanner(System.in);System.out.println("请输入查找关键字(姓名 学号 性别 年龄 重量 身高 爱好 或者 全部信息)");String next = sc.next();switch (next){case "姓名":System.out.print("请输入要查找的姓名:");String name = sc.next();SelectByName(s, name);break;case "学号":System.out.print("请输入要查找的学号:");String id = sc.next();SelectById(s,id);break;case "性别":System.out.print("请输入要查找的性别:");String sex = sc.next();SelectBySex(s, sex);break;case "年龄":System.out.print("请输入要查找的年龄:");int age = sc.nextInt();SelectByAge(s, age);break;case "重量":System.out.print("请输入要查找的重量:");double weight = sc.nextDouble();SelectByWeight(s,weight);break;case "身高":System.out.print("请输入要查找的身高:");double hight = sc.nextDouble();SelectByHeight(s,hight);break;case "爱好":System.out.print("请输入要查找的爱好:");String s1 = sc.nextLine();SelectByHobby(s,s1);break;case "全部信息":System.out.print("请输入要查找的姓名:");Student s2 = new Student();s2.setName(sc.next());System.out.print("请输入要查找的学号:");s2.setId(sc.next());System.out.print("请输入要查找的性别:");s2.setGender(sc.next());System.out.print("请输入要查找的年龄:");s2.setAge(sc.nextInt());System.out.print("请输入要查找的重量:");s2.setWeight(sc.nextDouble());System.out.print("请输入要查找的身高:");s2.setHight(sc.nextDouble());System.out.print("请输入要查找的爱好:");String n = sc.next();String[] split = n.split(",");s2.setHobby(split);SelectByAll(s,s2);}}//查找全部public static void SelectByAll(ArrayList<Student> s,Student s1){int flag = 0;for (Student student : s) {if(s1.toString().equals(student.toString())){System.out.println(student);flag=1;}}if(flag==0){System.out.println("!!!数据文件里面没有要查找的人!!!");System.out.println();}}//查找爱好public static void SelectByHobby(ArrayList<Student> s ,String h){String[] split = h.split(" ");String s1 = split.toString();System.out.println(s1);int flag = 0;for (Student student : s) {if(s1.equals(student.getHobby().toString())){System.out.println(student);flag=1;}}if(flag==0){System.out.println("!!!数据文件里面没有要查找的人!!!");System.out.println();}}//查找身高private static void SelectByHeight(ArrayList<Student> s ,double w) {int flag = 0;for (Student student : s) {if(w==student.getHight()){System.out.println(student);flag=1;}}if(flag==0){System.out.println("!!!数据文件里面没有要查找的人!!!");System.out.println();}}//    查找体重private static void SelectByWeight(ArrayList<Student> s ,double w) {int flag = 0;for (Student student : s) {if(w==student.getWeight()){System.out.println(student);flag=1;}}if(flag==0){System.out.println("!!!数据文件里面没有要查找的人!!!");System.out.println();}}//    查找年龄private static void SelectByAge(ArrayList<Student> s ,int age) {int flag = 0;for (Student student : s) {if(age==student.getAge()){System.out.println(student);flag=1;}}if(flag==0){System.out.println("!!!数据文件里面没有要查找的人!!!");System.out.println();}}//    查找性别private static void SelectBySex(ArrayList<Student> s ,String sex) {int flag = 0;for (Student student : s) {if(sex.equals(student.getGender())){System.out.println(student);flag=1;}}if(flag==0){System.out.println("!!!数据文件里面没有要查找的人!!!");System.out.println();}}//    查找idprivate static void SelectById(ArrayList<Student> s ,String id) {int flag = 0;for (Student student : s) {if(id.equals(student.getId())){System.out.println(student);flag=1;}}if(flag==0){System.out.println("!!!数据文件里面没有要查找的人!!!");System.out.println();}}//    查找名字public static void SelectByName(ArrayList<Student> s ,String next){int flag = 0;for (Student student : s) {if(next.equals(student.getName())){System.out.println(student);flag=1;}}if(flag==0){System.out.println("!!!数据文件里面没有要查找的人!!!");System.out.println();}}//    由文件中读取出来,返回一个ArrayList集合public static ArrayList<Student> read() throws Exception {BufferedReader br = new BufferedReader(new FileReader("StudentInfo.txt"));String line;ArrayList<Student> student = new ArrayList<>();//将学生信息由StudentInfo中读取进来,加载进ArrayList中while((line=br.readLine())!=null){Student Stu = new Student();String[] s = line.split(" ");String[] split = s[s.length-1].split(",");Stu.setName(s[0]);Stu.setId(s[1]);Stu.setGender(s[2]);Stu.setAge(Integer.parseInt(s[3]));Stu.setWeight(Double.parseDouble(s[4]));Stu.setHight(Double.parseDouble(s[5]));Stu.setHobby(split);student.add(Stu);}return student;}//写入或者加入一个学生对象public static Student wir() throws Exception{Scanner sc = new Scanner(System.in);BufferedWriter bw = new BufferedWriter(new FileWriter("StudentInfo.txt",true));Student stu = new Student();System.out.println("请输入学生的信息(按照 姓名 学号 性别 年龄 重量 身高 爱好填写)");//写入文件String info = sc.nextLine();bw.write(info);bw.newLine();bw.flush();bw.close();//加载成对象Student Stu = new Student();String[] s = info.split(" ");String[] split = s[s.length-1].split(",");Stu.setName(s[0]);Stu.setId(s[1]);Stu.setGender(s[2]);Stu.setAge(Integer.parseInt(s[3]));Stu.setWeight(Double.parseDouble(s[4]));Stu.setHight(Double.parseDouble(s[5]));Stu.setHobby(split);return Stu;}
}

StudentManageSystem(学生管理系统)相关推荐

  1. C语言基于链表的学生管理系统,超详细

    基于链表的学生管理系统 基于链表的学生管理系统 前言 功能 整体思路 Function.h Function.cpp 主文件StudentManageSystem.cpp 各函数详细说明 保存 读取 ...

  2. 用python设计学生管理系统_python+tkinter实现学生管理系统

    本文实例为大家分享了python+tkinter实现学生管理系统的具体代码,供大家参考,具体内容如下 from tkinter import * from tkinter.messagebox imp ...

  3. python删除字典中性别为男_python初学者,用python3实现基本的学生管理系统代码实例...

    本篇文章主要分享python学生管理系统的使用,文章非常详细地介绍了通过示例代码实现的学生管理系统,该系统对每个人的研究或工作都有一定的参考学习价值,希望你能在其中有所收获. 这个是用python实现 ...

  4. 学生管理系统(C语言版)

    学生管理系统 这个是大一学习C语言的时候做的一个小项目,代码部分基本都是自己一人完成,没用到什么高大上的技术,在图形化方面用了EasyX(一个C++的图形库),其他都是C语言的基础内容. 项目介绍 项 ...

  5. 用JDBC写一个学生管理系统(添加、删除、修改、查询学生信息)(二)

    本文上接用JDBC写一个学生管理系统(添加.删除.修改.查询学生信息) 这次主要是对上一文中的查询方法做一下调整,用创建内部类的方法来实现学生信息的查询. 我们先要定义一个接口IRowMapper: ...

  6. 用JDBC写一个学生管理系统(添加、删除、修改、查询学生信息)

    首先需要用Navicat Premium创建一个student表 用Java连接好MySQL数据库(需要copy一个mysql-connector-java-5.1.44-bin.jar包,该包可在网 ...

  7. python大作业 学生管理系统 以Excel(xls)格式导入文件

    简单的说一下每个板块的作用 这个load函数,是导入进来文件的数据 def load():data=xlrd.open_workbook('data.xls')table=data.sheets()[ ...

  8. JAVA入门到精通-第73讲-学生管理系统5-dao.sqlhelper

    -Model2模式 如果数据模型会很多,怎么办? 处理业务逻辑的:Model层 后台又分为:处理业务逻辑和对数据库的操作DAO-data access object -决定,再抽象一层出来:数据模型: ...

  9. java管理系统用怎么框架做_java 使用servlet做学生管理系统(无框架)

    使用工具: JavaJDK1.8 32位 Tomcat 8.5.33 32位 IDEA MySQL5.6 使用Jar包: c3p0-0.9.1.2.jar commons-dbutils-1.4.ja ...

  10. 基于BootStrap,FortAweSome,Ajax的学生管理系统

    一. 基于BootStrap,FortAweSome,Ajax的学生管理系统代码部分 1.students.html <1>html页面文件 <!DOCTYPE html> & ...

最新文章

  1. 利用74LS138实现4-16译码器,并在QuartusⅡ上进行仿真
  2. 你遇到过哪些理工科的实验高手,他们有哪些优秀的思维习惯?
  3. 找回Python IDLE Shell里的历史命令(用上下键翻历史命令怎么不好用了呢?)
  4. ubuntu20.04的xfce4下面安装百度输入法linux版本
  5. 面具公园登陆不了未能找到服务器,面具公园之后,伴圈app成为了新的替代
  6. 【Kafka】 kafka 启动 Connection to node 1 could not be established. Broker may not be available
  7. 更换用户目录后conda环境配置
  8. 软件测试,我是女生适合吗?我30岁了能学会吗?我大专毕业能做吗?
  9. Apache 的 httpd.conf 详解(很实用)
  10. apt-get pip3
  11. VScode配置go空格缩进替代tab
  12. 怎么p出模糊的照片_照片模糊了怎么办 如何利用美图秀秀变清晰
  13. saltstack数据返回和模块定义
  14. 脑电分析系列[MNE-Python-7]| Python读取.edf文件
  15. matlab 画思维图像,「4」图像思维
  16. 苹果m1芯片相当于什么水平
  17. Android FFmpegMediaMetadataRetriever获取歌曲的作者
  18. [转]int转string string转int
  19. 物理层的传输介质和设备
  20. python 本地离线安装whl文件

热门文章

  1. 基于HTML、CSS、JavaScript、jQuery的app小项目--简易备忘录
  2. JAVA用OpenCV做AI图片处理
  3. 理解openssl协议:x509、crt、cer、key、csr、ssl、tls 这些都是什么鬼? 如何给自己网站颁发证书?
  4. detecting android sdk, Select Android SDK directory
  5. 农夫山泉 || 到底是如何缔造年140亿销售神话的?
  6. 我的世界里 有你还不知道的秘密 边走边学习 且行且珍惜吧
  7. 图片上传之blob对象预览
  8. OpenHarmony 3.2 Release HDF的IDL文件初探(上)
  9. 暴走英雄坛服务器维修,暴走英雄坛采集位置及注意事项一览
  10. IoT产品安全基线(一)硬件安全