Simple student information management system based on JAVA (with source code)

I. Introduction    

       I am learning JAVA recently. After learning the basics from online videos these days, I made a student information management system. Please correct me where it is appropriate!

        The student information management system mainly includes: displaying student information; adding student information; finding student information; deleting student information; modifying student information; sorting by grade; counting the total number of students. The information entered into the student includes student number, name, gender, age, date of birth, college, and grades.

2. Main functions of the system

        The student information management system mainly includes:

                1. Display student information;

                2. Add student information;

                3. Find student information;

                4. Delete student information;

                5. Modify student information;

                6. Sort by grades;

                7. Count the total number of students;

3. Realization of the main functions of the system

        Let's start to introduce the code. Detailed comments are given at the main code. If there is something you don't understand, please leave a message in the comment area.

  • Student information management system function menu

        The main interface function code part, this function mainly prints out the prompt information selected by the function key of the student information management system to form a simple login interface.

The implementation method is as follows:

static void show1(){
        System.out.println("********************************************************");
        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("**************        6.按照成绩排序        **************");
        System.out.println("**************        7.统计学生信息        **************");
        System.out.println("**************        0.退出系统           **************");
        System.out.println("********************************************************");
        System.out.print("请选择其功能:");
    }

The realization effect is shown in the figure:

  • display student information

        This function is to display all the initially stored student information.

The implementation method is as follows:

static void show(){                     //显示学生信息
        System.out.println("******************************************学生信息表************************************************");
        System.out.println("序号\t\t\t学号\t\t\t姓名\t\t\t\t性别\t\t\t年龄\t\t\t出生日期\t\t\t学院\t\t\t\t成绩");
        for (int i = 0; i < students.size(); i++) {
            final Student student = students.get(i);
            System.out.println(i + 1 + "\t\t" + student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"
                    +student.getAge() + "\t\t\t" +student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());
        }
        System.out.println("**************************************************************************************************");
    }

The realization effect is shown in the figure:

  • Add student information

The implementation method is as follows:

static void add(){                      //增加学生信息
        System.out.print("请输入您要添加学生的个数:");
        int s = sc.nextInt();
        for (int i = 0; i < s; i++) {
            System.out.print("请输入您要添加的学号:");
            String str = sc.next();
            int count = 0;
            for (final Student student : students) {
                if (student.getId().equals(str)) {
                    System.out.println("已有此人!");
                    break;
                }
                count++;
            }
            if (count == students.size()){
                System.out.print("姓名:");
                String str1 = sc.next();
                System.out.print("性别:");
                String str2 = sc.next();
                System.out.print("年龄:");
                String str3 = sc.next();
                System.out.print("出生日期(yyyy-mm-dd):");
                String str4 = sc.next();
                System.out.print("学院:");
                String str5 = sc.next();
                System.out.print("成绩:");
                int str6 = sc.nextInt();
                Student student = new Student(str,str1,str2,str3,str4,str5,str6);
                students.add(student);
                System.out.println("添加成功!");
            }
        }
    }

The realization effect is shown in the figure:

  • Find Student Information

        The main function of this function is to query by student number when querying, and output a prompt message if there is no such person.

The implementation method is as follows:

static void search(){                          //查找学生信息
        System.out.print("请输入您要查找的学号:");
        String str = sc.next();
        int count = 0;
        for (final Student student : students) {
            if (student.getId().equals(str)) {
                System.out.println(student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"
                        + student.getAge() + "\t\t\t" + student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());
                break;
            }
            count++;
        }
        if (count == students.size()){
            System.out.println("查无此人!");
        }
    }

The realization effect is shown in the figure:

  • delete student information

        The main function of this function is to perform a delete operation, enter the student number to search, and delete the student information after finding the student information.

The implementation method is as follows:

static void delete(){                       //删除学生信息
        System.out.print("请输入您要删除的学号:");
        String str = sc.next();
        int a = students.size();
        int count = 0;
        for (int i = 0; i < students.size(); i++) {
            final Student student = students.get(i);
            if (student.getId().equals(str)){
                students.remove(i);
                System.out.println("删除成功!");
                break;
            }
            count++;
        }
        if (count == a){
            System.out.println("查无此人!");
        }
    }

The realization effect is shown in the figure:

  • Modify student information

        The main function of this function is to modify the student information. After entering the student number and querying the student information, modify the student information.

The implementation method is as follows:

static void modify() {                          //修改学生信息
        System.out.print("请输入您要修改的学号:");
        String str = sc.next();
        int count = 0;
        for (final Student student : students) {
            if (student.getId().equals(str)) {
                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("**********      6.成绩       *********");
                    System.out.println("**************************************");
                    System.out.print("请输入您要修改的选项:");
                    int a = sc.nextInt();
                    if (a == 1 || a == 2 || a == 3 || a == 4 || a == 5 || a == 6) {
                        System.out.print("修改为:");
                        String str0 = sc.next();
                        switch (a) {
                            case 1 -> student.setName(str0);
                            case 2 -> student.setSex(str0);
                            case 3 -> student.setBirthday(str0);
                            case 4 -> student.setAge(str0);
                            case 5 -> student.setCollege(str0);
                            case 6 -> student.setGrade(Integer.parseInt(str0));
                        }
                        System.out.println("修改成功!");
                        break;
                    } else {
                        System.out.println("请输入正确的序号!");
                    }
                }
                break;
            }
            count++;
        }
        if (count == students.size()){
            System.out.println("查无此人!");
        }
    }

The realization effect is shown in the figure:

  • Sort by grade

        This function is mainly to sort students in descending order based on their grades.

The implementation method is as follows:

static void sort(){                         //按照成绩排序
        int [][]grade = new int[students.size()][2];
        for (int i = 0; i < students.size(); i++) {
            final Student student = students.get(i);
            grade[i][0] = student.getGrade();
            grade[i][1] = i;
        }
        for (int i = 0; i < students.size(); i++) {
            for (int j = 1; j < students.size() - i; j++) {
                if (grade[j - 1][0] > grade[j][0]){
                    int a = grade[j][0];
                    grade[j][0] = grade[j - 1][0];
                    grade[j - 1][0] = a;
                    int c = grade[j][1];
                    grade[j][1] = grade[j - 1][1];
                    grade[j - 1][1] = c;
                }
            }
        }
        for (int i = students.size() - 1; i >= 0; i--) {
            final Student student = students.get(grade[i][1]);
            System.out.println(student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"
                    + student.getAge() + "\t\t\t" + student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());
        }
    }

The realization effect is shown in the figure:

  • Total number of students

The implementation method is as follows: 

static void count(){                        //统计学生总数
        System.out.println("学生总人数为:" + students.size());
    }

The realization effect is shown in the figure:

Full code:

Student.java

public class Student {
    private String id;                          //学号
    private String name;                        //姓名
    private String sex;                         //性别
    private String age;                         //年龄
    private String birthday;                    //出生日期
    private String college;                     //学院
    private int grade;                          //成绩

    public Student() {
    }

    public Student(String id, String name, String sex, String age, String birthday, String college, int grade) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.birthday = birthday;
        this.college = college;
        this.grade = grade;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getCollege() {
        return college;
    }

    public void setCollege(String college) {
        this.college = college;
    }

    public int getGrade() {
        return grade;
    }

    public void setGrade(int grade) {
        this.grade = grade;
    }
}

test.java

import java.util.ArrayList;
import java.util.Scanner;

public class test {
    static ArrayList<Student> students = new ArrayList<>();                 //定义学生集合
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        show0();
        while (true) {
            show1();
            int a = sc.nextInt();
            if (a == 0){
                break;
            }
            switch (a) {
                case 1 -> show();
                case 2 -> add();
                case 3 -> delete();
                case 4 -> modify();
                case 5 -> search();
                case 6 -> sort();
                case 7 -> count();
                default -> System.out.println("请输入正确序号!");
            }
        }
    }

    static void show0(){                    //录入初始学生信息
        Student student = new Student("54213460501","许雅静","男","45","2002-01-24","软件学院",98);
        Student student1 = new Student("54213460502","段清堂","女","25","2002-07-24","通信学院",78);
        Student student2 = new Student("54213460503","曲双红","男","36","2002-04-14","外语学院",69);
        Student student3 = new Student("54213460504","伍四六","女","29","2001-09-21","国教学院",97);
        Student student4 = new Student("54213460505","葛瑞格","男","45","2002-01-24","艺设学院",82);
        students.add(student);students.add(student1);students.add(student2);students.add(student3);students.add(student4);
    }

    static void show1(){
        System.out.println("********************************************************");
        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("**************        6.按照成绩排序        **************");
        System.out.println("**************        7.统计学生信息        **************");
        System.out.println("**************        0.退出系统           **************");
        System.out.println("********************************************************");
        System.out.print("请选择其功能:");
    }
    static void show(){                     //显示学生信息
        System.out.println("******************************************学生信息表************************************************");
        System.out.println("序号\t\t\t学号\t\t\t姓名\t\t\t\t性别\t\t\t年龄\t\t\t出生日期\t\t\t学院\t\t\t\t成绩");
        for (int i = 0; i < students.size(); i++) {
            final Student student = students.get(i);
            System.out.println(i + 1 + "\t\t" + student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"
                    +student.getAge() + "\t\t\t" +student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());
        }
        System.out.println("**************************************************************************************************");
    }

    static void add(){                      //增加学生信息
        System.out.print("请输入您要添加学生的个数:");
        int s = sc.nextInt();
        for (int i = 0; i < s; i++) {
            System.out.print("请输入您要添加的学号:");
            String str = sc.next();
            int count = 0;
            for (final Student student : students) {
                if (student.getId().equals(str)) {
                    System.out.println("已有此人!");
                    break;
                }
                count++;
            }
            if (count == students.size()){
                System.out.print("姓名:");
                String str1 = sc.next();
                System.out.print("性别:");
                String str2 = sc.next();
                System.out.print("年龄:");
                String str3 = sc.next();
                System.out.print("出生日期(yyyy-mm-dd):");
                String str4 = sc.next();
                System.out.print("学院:");
                String str5 = sc.next();
                System.out.print("成绩:");
                int str6 = sc.nextInt();
                Student student = new Student(str,str1,str2,str3,str4,str5,str6);
                students.add(student);
                System.out.println("添加成功!");
            }
        }
    }

    static void delete(){                       //删除学生信息
        System.out.print("请输入您要删除的学号:");
        String str = sc.next();
        int a = students.size();
        int count = 0;
        for (int i = 0; i < students.size(); i++) {
            final Student student = students.get(i);
            if (student.getId().equals(str)){
                students.remove(i);
                System.out.println("删除成功!");
                break;
            }
            count++;
        }
        if (count == a){
            System.out.println("查无此人!");
        }
    }

    static void modify() {                          //修改学生信息
        System.out.print("请输入您要修改的学号:");
        String str = sc.next();
        int count = 0;
        for (final Student student : students) {
            if (student.getId().equals(str)) {
                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("**********      6.成绩       *********");
                    System.out.println("**************************************");
                    System.out.print("请输入您要修改的选项:");
                    int a = sc.nextInt();
                    if (a == 1 || a == 2 || a == 3 || a == 4 || a == 5 || a == 6) {
                        System.out.print("修改为:");
                        String str0 = sc.next();
                        switch (a) {
                            case 1 -> student.setName(str0);
                            case 2 -> student.setSex(str0);
                            case 3 -> student.setBirthday(str0);
                            case 4 -> student.setAge(str0);
                            case 5 -> student.setCollege(str0);
                            case 6 -> student.setGrade(Integer.parseInt(str0));
                        }
                        System.out.println("修改成功!");
                        break;
                    } else {
                        System.out.println("请输入正确的序号!");
                    }
                }
                break;
            }
            count++;
        }
        if (count == students.size()){
            System.out.println("查无此人!");
        }
    }

    static void search(){                          //查找学生信息
        System.out.print("请输入您要查找的学号:");
        String str = sc.next();
        int count = 0;
        for (final Student student : students) {
            if (student.getId().equals(str)) {
                System.out.println(student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"
                        + student.getAge() + "\t\t\t" + student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());
                break;
            }
            count++;
        }
        if (count == students.size()){
            System.out.println("查无此人!");
        }
    }

    static void sort(){                         //按照成绩排序
        int [][]grade = new int[students.size()][2];
        for (int i = 0; i < students.size(); i++) {
            final Student student = students.get(i);
            grade[i][0] = student.getGrade();
            grade[i][1] = i;
        }
        for (int i = 0; i < students.size(); i++) {
            for (int j = 1; j < students.size() - i; j++) {
                if (grade[j - 1][0] > grade[j][0]){
                    int a = grade[j][0];
                    grade[j][0] = grade[j - 1][0];
                    grade[j - 1][0] = a;
                    int c = grade[j][1];
                    grade[j][1] = grade[j - 1][1];
                    grade[j - 1][1] = c;
                }
            }
        }
        for (int i = students.size() - 1; i >= 0; i--) {
            final Student student = students.get(grade[i][1]);
            System.out.println(student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"
                    + student.getAge() + "\t\t\t" + student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());
        }
    }

    static void count(){                        //统计学生总数
        System.out.println("学生总人数为:" + students.size());
    }
}

Four. Summary

        The above is my plan to implement the student information management system. This article only introduces the implementation plan and production process, which is for reference only. If you have any questions, please leave a message and point out. Welcome to exchange and learn.

Guess you like

Origin blog.csdn.net/m0_69500357/article/details/128164858