• 用集合实现一个控制台版的学生管理系统


    public class Student {
        private int id;
        private String name;
        private int age;
        private String classNum;
    
        public Student() {
    
        }
    
        public Student(int id, String name, int age, String classNum) {
            this.id = id;
            this.name = name;
            this.age = age;
            this.classNum = classNum;
        }
    
        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 String getClassNum() {
            return classNum;
        }
    
        public void setClassNum(String classNum) {
            this.classNum = classNum;
        }
    
        public String toString() {
            return "学号:" + this.id + "	姓名:" + this.name + "	年龄:" + this.age + "	班级编号:" + this.classNum;
        }
    
    }
    import java.util.List;
    
    public class StudentManager {
        /**
         * 显示所有学生信息的方法
         */
        public void showAllStudentInfo(List<Student> stus) {
            for (Student student : stus) {
                System.out.println(student);
            }
        }
    
        /**
         * 根据学员学号查询
         */
        public void getStudentById(int id, List<Student> stus) {
            int count = 0;
            for (Student student : stus) {
                if (student.getId() == id) {
                    System.out.println(student);
                } else {
                    count++;
                }
            }
            if (count == stus.size()) {
                System.out.println("没有该学号的学员");
            }
        }
    
        /**
         * 根据学员学号删除学生信息
         */
        public void deleteById(int id, List<Student> stus) {
            int index = 0;
            for (int i = 0; i < stus.size(); i++) {
                Student student = stus.get(i);
                if (student.getId() == id) {
                    index = i;
                    break;
                }
            }
            stus.remove(index);
        }
    
        /**
         * 根据学号修改学员信息
         */
        public void updateStudent(int uid, List<Student> stus, Student student) {
            int index = 0;
            for (int i = 0; i < stus.size(); i++) {
                if (stus.get(i).getId() == uid) {
                    index = i;
                    break;
                }
            }
            stus.set(index, student);
        }
    
    }
    import java.util.List;
    
    public class StudentManager {
        /**
         * 显示所有学生信息的方法
         */
        public void showAllStudentInfo(List<Student> stus) {
            for (Student student : stus) {
                System.out.println(student);
            }
        }
    
        /**
         * 根据学员学号查询
         */
        public void getStudentById(int id, List<Student> stus) {
            int count = 0;
            for (Student student : stus) {
                if (student.getId() == id) {
                    System.out.println(student);
                } else {
                    count++;
                }
            }
            if (count == stus.size()) {
                System.out.println("没有该学号的学员");
            }
        }
    
        /**
         * 根据学员学号删除学生信息
         */
        public void deleteById(int id, List<Student> stus) {
            int index = 0;
            for (int i = 0; i < stus.size(); i++) {
                Student student = stus.get(i);
                if (student.getId() == id) {
                    index = i;
                    break;
                }
            }
            stus.remove(index);
        }
    
        /**
         * 根据学号修改学员信息
         */
        public void updateStudent(int uid, List<Student> stus, Student student) {
            int index = 0;
            for (int i = 0; i < stus.size(); i++) {
                if (stus.get(i).getId() == uid) {
                    index = i;
                    break;
                }
            }
            stus.set(index, student);
        }
    
    }
  • 相关阅读:
    Codeforces Round #388(div 2)
    Codeforces Round #387(div 2)
    Codeforces Round #386(div 2)
    Codeforces Round #385(div 2)
    Codeforces Round #384(div 2)
    Wannafly Union Goodbye 2016
    写在2016的最后一天——给未来的自己
    2016HDU校赛
    2016BUAA校赛决赛
    codevs 1344 模拟退火
  • 原文地址:https://www.cnblogs.com/lujing-newer/p/6567700.html
Copyright © 2020-2023  润新知