欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

学生成绩教务管理系统(学生类与学生管理类代码)

程序员文章站 2022-12-20 13:16:26
Student类:public class Student { private int id; private String name; private int age; private double score; @Override public String toString() { return "Student{" + "id=" + id + ", name='"...

Student类:

public class Student { private int id; private String name; private int age; private double score; @Override public String toString() { return "Student{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + ", score=" + score + '}'; } public Student() { } public Student(int id, String name, int age, double score) { this.id = id; this.name = name; this.age = age; this.score = score; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public double getScore() { return score; } public void setScore(double score) { this.score = score; } } 

main函数:Studentmanagement

 import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class StudentManagement { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); List<Student> list = new ArrayList<Student>(); boolean b = false; while (true){ 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("请输入你的选择:"); int input = scanner.nextInt(); switch (input){ case 1: addStudent(list); break; case 2: removeStudent(list); break; case 3: setStudent(list); break; case 4: getStudent(list); break; case 5: System.out.println("谢谢使用本教务系统,祝你开开心心"); b = true; scanner.close(); break; default: System.out.println("输入有误!!!请输入1-5"); break; } if (b == true){ break; } } } public static void addStudent(List<Student> list){ boolean aa = true; int id = 0; System.out.println("请输入学生的学号:"); while (true){ id = new Scanner(System.in).nextInt(); for (int i = 0; i < list.size();i++){ Student student2 = list.get(i); if (id == student2.getId()){ aa = false; System.out.println("该学号已存在,请重新输入学号:"); break; }else { aa = true; } } if (aa == true){ break; } } Student student = new Student(); student.setId(id); System.out.println("请输入学生的姓名:"); student.setName(new Scanner(System.in).next()); System.out.println("请输入学生的年龄:"); student.setAge(new Scanner(System.in).nextInt()); System.out.println("请输入学生的成绩:"); student.setScore(new Scanner(System.in).nextDouble()); list.add(student); System.out.println("信息录入完毕"); } public static void removeStudent(List<Student> list){ if (list.size() == 0){ System.out.println("本系统无学生信息,录入后才能进行删除"); return; } System.out.println("请输入要删除学生的学号:"); int id = 0; boolean aa = true; while (true){ id = new Scanner(System.in).nextInt(); for (int i = 0; i < list.size();i++){ Student student2 = list.get(i); if (id == student2.getId()){ aa = true; list.remove(student2); System.out.println("学号为"+id+"的学生已被移除"); break; }else { aa = false; System.out.println("该学号不存在,请重新输入学号:"); } } if (aa == true){ break; } } } public static void setStudent(List<Student> list){ System.out.println("请输入要修改学生的学号:"); int id = 0; boolean aa = true; while (true){ id = new Scanner(System.in).nextInt(); for (int i = 0; i < list.size();i++){ Student student = list.get(i); if (id == student.getId()){ aa = true; System.out.println("请输入学生的学号:"); student.setId(new Scanner(System.in).nextInt()); System.out.println("请输入学生的姓名:"); student.setName(new Scanner(System.in).next()); System.out.println("请输入学生的年龄:"); student.setAge(new Scanner(System.in).nextInt()); System.out.println("请输入学生的成绩:"); student.setScore(new Scanner(System.in).nextDouble()); System.out.println("该学生信息修改完成"); break; }else { aa = false; System.out.println("该学号不存在,请重新输入学号:"); } } if (aa == true){ break; } } } public static void getStudent(List<Student> list){ if (list.size() == 0){ System.out.println("本系统无学生信息,请录入后在查询"); return; } System.out.println("本年级总学生人数为"+list.size()+",具体信息如下:"); for (int i = 0; i < list.size();i++){ Student student = list.get(i); System.out.println(student); } } } 

本文地址:https://blog.csdn.net/Mrxuanshen/article/details/108028348

相关标签: Java基础 java