java集合实现“智能妲己”学生管理系统

阅读: 评论:0

java集合实现“智能妲己”学生管理系统

java集合实现“智能妲己”学生管理系统

前言:

最近在佛系java,用java两个小时用集合做出来了一个小项目,基于java的学生管理系统,那么为什莫要用“智能妲己”这个词呢,不急,代码一看你就会知道我为什莫这样叫了,首先这个小项目只是用来练手用的,做的在功能上还不太完善,对它感兴趣的童鞋可以来进行升级,对了,升级好了,一定要高数我哦,哦,是告诉,嘿嘿。

 

首先是学生类的实体类:当你写好private这些变量后,直接后面的get啊,set啊就可以直接生成了,IDea快捷键:Fn+Alt+insert

 

package MyStudentManger;public class Student {private String name;private String id;private String age;private String address;public Student() {}public Student(String name, String id, String age, String address) {this.name = name;this.id = id;this.age = age;this.address = address;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}
}

紧接着是主菜单:

package MyStudentManger;import java.util.ArrayList;
import java.util.Scanner;public class StudentMain {public static void main(String[] args) {//创建集合对象,用于存储学生信息ArrayList<Student> array=new ArrayList<>();while(true) {System.out.println("---***欢迎来到学生管理系统,妲己为主人服务***---");System.out.println("1.添加学生*****2.修改学生*****3.删除学生*****4.查看学生*****5.退出系统");System.out.println("请主人输入上面的指令:");Scanner sc = new Scanner(System.in);String line = sc.nextLine();switch (line)//在jdk7后允许使用字符串{case "1":addStudent(array);break;case "2":updateStudent(array);break;case "3":DeleteStudent(array);break;case "4":FindStudent(array);break;case "5":System.out.println("谢谢使用");it(0);default:System.out.println("主人输入的指令有误,请主人重新输入");}}}

再接着是几个方法:

  //添加学生public static void addStudent(ArrayList<Student> array) {//键盘录入学生对象的信息,并显示提示信息Scanner s = new Scanner(System.in);String id;//为了让被使用的学号能够返回到这里,继续重新输入学号,这里采用循环进行实现while (true) {System.out.println("请输入要添加学生的ID:");id = s.nextLine();boolean flag = isUsed(array, id);if (flag) {System.out.println("主人不能输入相同的ID哦!");} else {break;}}System.out.println("请输入要添加的学生姓名:");String name = s.nextLine();System.out.println("请输入要添加学生的年龄:");String age = s.nextLine();System.out.println("请输入要添加学生的地址:");String address = s.nextLine();//创建学生对象,添加到集合中Student stu = new Student();stu.setName(name);stu.setId(id);stu.setAge(age);stu.setAddress(address);array.add(stu);//给出提示信息System.out.println("恭喜主人,录入成功!");}//学号重复问题public static boolean isUsed(ArrayList<Student> array, String id) {boolean flag = false;for (int i = 0; i < array.size(); i++) {Student s = (i);if (s.getId().equals(id)) {flag = true;break;}}return flag;}//删除学生信息public static void DeleteStudent(ArrayList<Student> array) {System.out.println("请主人要删除的学号:");Scanner sc = new Scanner(System.in);String id = sc.nextLine();int index = -1;//判断删除的学生信息不存在的Flagfor (int i = 0; i < array.size(); i++) {Student s = (i);if (s.getId().equals(id)) {index = i;break;}}if (index == -1) {System.out.println("该学号不存在");} else {ve(index);System.out.println("恭喜主人,该学生已经从战场上退出");}}//修改学生信息public static void updateStudent(ArrayList<Student> array) {//创建学生对象Student st = new Student();Scanner sc = new Scanner(System.in);String id;while (true) {System.out.println("请主人输入要修改学生的学号,我将根据学号为您修改:");id = sc.nextLine();//遍历修改对象信息int index = -1;for (int i = 0; i < array.size(); i++) {Student student = (i);if (Id().equals(id)) {index = i;break;}}if (index == -1) {System.out.println("妲己暂未找到该学号,请您重新输入");} else {array.set(index, st);break;}}System.out.println("请输入要修改为新学生的姓名:");String name = sc.nextLine();System.out.println("请输入要修改为新学生的年龄:");String age = sc.nextLine();System.out.println("请输入要修改为新学生的地址:");String address = sc.nextLine();//添加对象st.setId(id);st.setName(name);st.setAge(age);st.setAddress(address);System.out.println("恭喜主人,该学生的装备已升级");}//查看学生public static void FindStudent(ArrayList<Student> array) {if (array.size() == 0) {System.out.println("请主人先输入信息,才能进行查看哦!");//return;用来返回空,不让程序继续执行return;}//显示表头System.out.println("学号tt姓名tt年龄tt地址");//循环遍历显示for (int i = 0; i < array.size(); i++) {Student s = (i);System.out.Id() + "tt" + s.getName() + "tt" + s.getAge() + "岁" + "t" + s.getAddress());}}}

本文发布于:2024-01-30 19:31:00,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170661426122304.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:管理系统   妲己   智能   学生   java
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23