如何获取Java学生管理系统的完整源码?

这是一个Java学生管理系统的源码示例:,,“java,import java.util.ArrayList;,import java.util.Scanner;,,class Student {, String name;, int age;, String id;,, public Student(String name, int age, String id) {, this.name = name;, this.age = age;, this.id = id;, },},,public class StudentManagementSystem {, public static void main(String[] args) {, ArrayList students = new ArrayList();, Scanner scanner = new Scanner(System.in);,, while (true) {, System.out.println("1. 添加学生");, System.out.println("2. 删除学生");, System.out.println("3. 修改学生信息");, System.out.println("4. 查看所有学生");, System.out.println("5. 退出系统");, System.out.print("请输入操作序号:");, int choice = scanner.nextInt();,, switch (choice) {, case 1:, System.out.print("请输入学生姓名:");, String name = scanner.next();, System.out.print("请输入学生年龄:");, int age = scanner.nextInt();, System.out.print("请输入学生学号:");, String id = scanner.next();, students.add(new Student(name, age, id));, System.out.println("学生添加成功!");, break;, case 2:, System.out.print("请输入要删除的学生学号:");, String deleteId = scanner.next();, boolean found = false;, for (Student student : students) {, if (student.id.equals(deleteId)) {, students.remove(student);, System.out.println("学生删除成功!");, found = true;, break;, }, }, if (!found) {, System.out.println("未找到该学生!");, }, break;, case 3:, System.out.print("请输入要修改的学生学号:");, String updateId = scanner.next();, boolean updated = false;, for (Student student : students) {, if (student.id.equals(updateId)) {, System.out.print("请输入新的学生姓名:");, String newName = scanner.next();, System.out.print("请输入新的学生年龄:");, int newAge = scanner.nextInt();, student.name = newName;, student.age = newAge;, System.out.println("学生信息修改成功!");, updated = true;, break;, }, }, if (!updated) {, System.out.println("未找到该学生!");, }, break;, case 4:, System.out.println("所有学生信息如下:");, for (Student student : students) {, System.out.println("姓名:" + student.name + ",年龄:" + student.age + ",学号:" + student.id);, }, break;, case 5:, System.out.println("感谢使用学生管理系统!");, scanner.close();, return;, default:, System.out.println("无效的操作序号,请重新输入!");, break;, }, }, },},
// 学生类
class Student {
    private String name;
    private int age;
    private String id;
    public Student(String name, int age, String id) {
        this.name = name;
        this.age = age;
        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 String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + ''' +
                ", age=" + age +
                ", id='" + id + ''' +
                '}';
    }
}
// 学生管理类
class StudentManager {
    private List<Student> students;
    public StudentManager() {
        students = new ArrayList<>();
    }
    public void addStudent(Student student) {
        students.add(student);
    }
    public void removeStudent(String id) {
        students.removeIf(student > student.getId().equals(id));
    }
    public Student findStudent(String id) {
        for (Student student : students) {
            if (student.getId().equals(id)) {
                return student;
            }
        }
        return null;
    }
    public void printAllStudents() {
        for (Student student : students) {
            System.out.println(student);
        }
    }
}
// 主程序
public class Main {
    public static void main(String[] args) {
        StudentManager manager = new StudentManager();
        manager.addStudent(new Student("张三", 20, "001"));
        manager.addStudent(new Student("李四", 21, "002"));
        manager.addStudent(new Student("王五", 22, "003"));
        System.out.println("所有学生信息:");
        manager.printAllStudents();
        System.out.println("查找ID为002的学生:");
        Student student = manager.findStudent("002");
        if (student != null) {
            System.out.println(student);
        } else {
            System.out.println("未找到该学生");
        }
        System.out.println("删除ID为001的学生:");
        manager.removeStudent("001");
        manager.printAllStudents();
    }
}

这个简单的学生管理系统包括了添加、删除、查找和打印所有学生的功能,你可以根据需要扩展更多功能,例如修改学生信息、按照年龄排序等。

如何获取Java学生管理系统的完整源码?

小伙伴们,上文介绍了“java 学生管理系统源码”的内容,你了解清楚吗?希望对你有所帮助,任何问题可以给我留言,让我们下期再见吧。

原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/1185285.html

本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。

(0)
未希新媒体运营
上一篇 2024-10-08 13:10
下一篇 2024-10-08 13:10

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

产品购买 QQ咨询 微信咨询 SEO优化
分享本页
返回顶部
云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购 >>点击进入