Java design student achievement management system

1.1 Topics and requirements

Design a student performance ranking system

Implement the following functions:

(1) Possess the management function of grades (add, delete, sort);

(2) Have the statistical function of grades (highest score, lowest score, average score, pass rate, etc.);

(3) It has the function of querying grades by student number and name;

(4) Be able to deal with the problem of repeated student numbers;

Remarks: The results record the following information: class, student number, name, four grades (percentage system).

1.1.1 Works display

(1) The operation interface is as follows:

 (2) Function display:

(3) Function view (other function copy code to view by yourself)

 

 

1.2 Knowledge points involved in this system

(1) Student class Course class

(2) StudentList class

(3) switch conditional statement

(4) The implementation class ArrayList of the collection List

(5) if-else if-else conditional statement

(6) while loop and for loop

1.3 Put four classes in one package

1.4 The code is as follows

(1). Create a course class

public class Course {
    //学生成绩,四门成绩构建一个类
        private int politics;
        private int math;
        private int english;
        private int computer;

        public Course() {
        }

        public Course(int politics, int math, int english, int computer) {
            this.politics = politics;
            this.math = math;
            this.english = english;
            this.computer = computer;
        }

        public int getPolitics() {
            return politics;
        }

        public void setPolitics(int politics) {
            this.politics = politics;
        }

        public int getMath() {
            return math;
        }

        public void setMath(int math) {
            this.math = math;
        }

        public int getEnglish() {
            return english;
        }

        public void setEnglish(int english) {
            this.english = english;
        }

        public int getComputer() {
            return computer;
        }

        public void setComputer(int computer) {
            this.computer = computer;
        }


    }

(2). Create a student class

public class Student extends Course{
    private String classname;
    private String name;
    private String number;
    private Course a;

    public String getClassname() {
        return classname;
    }

    public void setClassname(String classname) {
        this.classname = classname;
    }

    public String getName() {
        return name;
    }

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

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public Course getA() {
        return a;
    }

    public void setA(Course a) {
        this.a = a;
    }
}

(3) Create a studentList class

package CourseDesign;

public class StudentList {

        private String name;
        private int sum;

        public StudentList(String name, int sum) {
            this.name = name;
            this.sum = sum;
        }

    public StudentList() {

    }

    public String getName() {
            return name;
        }

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

        public int getSum() {
            return sum;
        }

        public void setSum(int sum) {
            this.sum = sum;
        }
}

(4) Create the main class of studentmanager

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

public class StudentManager { 
    public static void main(String[] args) { 
        //Create ArrayList collection and store Student type variable 
        ArrayList<Student> arry1=new ArrayList<Student> (); 
        //Create an ArrayList collection and store the Course type variable 
        ArrayList<Course> arry2=new ArrayList<Course>(); 
        //Create an ArrayList collection and store the StudentList type variable 
        ArrayList<StudentList> arry3=new ArrayList<StudentList>() ; 
        while(true) { 
            System.out.println("------Welcome to the student achievement ranking system------"); 
            System.out.println("1 Add student achievement, and check the entry Result"); 
            System.out.println("2 delete student grades");
            System.out.println("3 Sort the grades of students, and output the highest and lowest grades"); 
            System.out.println("4 Check the average score and pass rate"); 
            System.out.println("5 No., name, or course name to query grades"); 
            System.out.println("6 View student grade entry results (unordered)"); 
            System.out.println("7 Exit"); 
            System.out.println( "Please enter your choice:"); 

            Scanner sc=new Scanner(System.in); 
            int num=sc.nextInt(); 
            //switch statement to complete related operations 
            switch(num) 
            { 
                case 1: 
                    //System.out .println("1 add student grade"); 
                    addStudent(arry1,arry2);
                    break;
                case 2:
                    //System.out.println("2 delete student grades"); println("2 delete student grades"); 
                    DeleteStudent(arry1);
                    break; 
                case 3: 
                    //System.out.println("3 sort students' grades, and output the highest and lowest grades"); 
                    sortStudent(arry1, arry3); 
                    break; 
                case 4: 
                    //System.out.println("4 check the average score and pass rate"); 
                    averagegStudent(arry1,arry2); 
                    break; 
                case 5: 
                    //System.out.println("5 press Student number, name, or course name query results"); 
                    searchStudent(arry1,arry2); 
                    break; 
                case 6: 
                    //System.out.println("View the results of student record entry (unordered)"); 
                    lookStudent(arry1,arry2); 
                    break; 
                case 7:
                    System.out.println("Thank you for using"); 
                    System.exit(0); //Terminate the currently running Java virtual machine 
            } 
        } 
    } 
    //Add student grades and check the entry results 
    public static void addStudent( ArrayList<Student > arry1,ArrayList<Course> arry2) 
    { 
        Scanner o=new Scanner(System.in); 
        System.out.println("Please enter several student information to be entered"); 
        int num=o.nextInt(); 
        for( int j=0;j<num;j++) { 
            System.out.println("Number" + (j + 1) + "score entry"); 
            Scanner sc = new Scanner(System.in); 
            //In order to allow the student number to be accessed outside the loop, define it outside the loop 
            String number;
            //In order to repeat the input of the student ID, the program can return here, use the loop 
            int a = sc.nextInt();
            while(true) { 
                System.out.println("Enter student number"); 
                number = sc.nextLine(); 
                boolean flag = isUsed(arry1, number); 
                if (flag) { 
                    System.out.println("Student Repeat number, please re-enter"); 
                } else { 
                    break; 
                } 
            } 
            System.out.println("Enter student name"); 
            String name = sc.nextLine(); 
            System.out.println("Enter student class"); 
            String classmate = sc.nextLine(); 
            System.out.println("Enter political grade"); 
            System.out.println("Enter math grade"); 
            int b = sc.nextInt(); 
            System.out.println("Enter English Grade"); 
            int d = sc.nextInt(); 
            System.out.println( "Input computer score"); 
            int e = sc.nextInt(); 
            //Create a student object and assign the value entered by the keyboard to the student member variable 
            Student stu = new Student(); 
            stu.setNumber(number); 
            stu.setName (name); 
            stu.setClassname(classmate); 
            //Create four grade objects, and assign the value entered by the keyboard to the member variable 
            Course c = new Course(); 
            c.setPolitics(a); 
            c.setMath(b); 
            c.setEnglish(d); 
            c.setComputer(e);
            //Add the reference variable to the collection 
            arry2.add(c); 
            stu.setA(c); 
            arry1.add(stu); 
        } 
    } 
    //Solve the problem of repeated student numbers 
    public static boolean isUsed(ArrayList<Student> arry1, String number) 
    { 
        boolean flag=false; 
        for(int i=0;i<arry1.size();i++) 
        { 
            Student stu=arry1.get(i); 
            if(stu.getNumber().equals(number)) 
            { 
                flag=true; 
                break; 
            } 
        } 
        return flag; 
    } 
    //Delete student grades
    public static void DeleteStudent(ArrayList<Student> arry1) 
    { 
                Scanner sc=new Scanner(System.in); 
                }else
                System.out.println("请输入要删除学生的学号");
                String number=sc.nextLine();
                int index=-1; 
                //Set the index to judge whether the student number exists 
                for(int i=0;i<arry1.size();i++) { 
                    //If the student number entered is the same as the student number in the system student collection Student 
                    s = arry1.get(i); 
                    if (s.getNumber().equals(number)) { 
                        index=i; 
                        break; 
                    } 
                } 
                if(index==-1) 
                { 
                    System.out.println("input The student number does not exist, please re-enter"); 
                { 
                    arry1.remove(index); 
            System.out.println("Delete the student successfully"); 
        } 

    } 
    //Check the student entry results (unordered) entry results 
    public static void lookStudent( ArrayList<Student> arry1,ArrayList<Course> arry2) 
    { 
        if(arry1.size()==0 ) 
        { 
            System.out.println("Please add student grades and search again"); 
        } 
        for(int i=0;i<arry1.size();i++ ) 
    { 
        Student st=arry1.get(i); 
        Course s =st.getA(); 
        System.out.println("------------------------------------ -------"); 
        System.out.println("Class\t\t\tName\t\tStudent Number\t\tCalculation\tEnglish\tMathematics\tPolitics");
        System.out.println(st.getClassname()+"\t"+st.getName()+"\t\t"+st.getNumber()+"\t\t"+s.getComputer()+" \t"+s.getEnglish()+"\t"+s.getMath()+"\t"+s.getPolitics()); 
        System.out.println("---------- -------------------------------------"); 
    } 
            StudentList a = new StudentList(); 
            int sum=arry1 .get(i).getA().getMath()+ arry1.get(i).getA().getEnglish()+ arry1.get(i).getA().getPolitics()+ arry1.get(i) .getA().getComputer();
            String name=arry1.get(i).getName();
   //Sort the grades of the students, and output the highest and lowest grades
}
    public static void sortStudent(ArrayList<Student> arry1,ArrayList<StudentList> arry3) 
    { 
        //sort the total scores of students 
        //how many students to sort 
        for(int i=0;i<arry1.size();i++) { 
            a.setName(name); 
            a.setSum(sum); 
            arry3.add(a); 
        } 
        int j = 0; 
        while( j<100) { 
            int index=0; 
            int i=0; 
            for ( i = 0; i < arry3.size(); i++) { 
                int max = arry3.get(0).getSum(); 
                if (max < arry3.get(i).getSum()) { 
                    max = arry3.get(i). getSum(); 
                    index=i; 
                }
            } 
            if(j==0) { 
                System.out.println("Name\t\t the highest total score"); 
                System.out.println(arry3.get(index).getName()+"\t\t "+arry3.get(index).getSum()); 
            }else if((i==arry3.size())&&(i-1)==0) 
            arry3.remove(index);
            if(arry3.size()==0)
            { 
                System.out.println("Name\t\t the lowest total score"); 
                System.out.println(arry3.get(index).getName()+"\t\t"+arry3.get(index) .getSum()); 
            }else { 

                System.out.println("Name\t\tTotal score"); 
                System.out.println(arry3.get(index).getName() + "\t\t" + arry3.get(index).getSum()); 
            } 
            j++; 
            { 
                break; 
            } 
        } 


    } 
    //Query results by student number, name, or course name 
    public static void searchStudent(ArrayList<Student> arry1,ArrayList<Course> arry2 ) { 
        Scanner sc = new Scanner(System.in); 
        System.out.println("Check grades by student number, name, or course name, press 1 for student number query, press 2 for name query"); 
        int a = sc.nextInt(); 
        if (a == 1) { 
            System.out.println("Please enter the student number"); 
            Scanner s = new Scanner(System.in); 
            String number = s.nextLine(); 
            for (int i = 0; i < arry1.size(); i++) { 
                if (arry1.get(i).getNumber().equals(number)) { 
                    System.out.println("--------------- ----------------------------"); 
                    System.out.println("Class\t\t\tName\t\t Student number\t\tcalculation\tEnglish\tmathematics\tpolitics");
                    System.out.println(arry1.get(i).getClassname() + "\t" + arry1.get(i).getName() + "\t\t" + arry1.get(i).getNumber() + "\t\t" + arry2.get(i).getComputer()+ "\t" + arry2.get(i).getEnglish() + "\t" +arry2.get(i).getMath() + "\t" + arry2.get(i).getPolitics());
                    System.out.println("--------------------------------------------");
                }
            }
        } else if (a == 2) {
            System.out.println("请输入姓名");
            Scanner c = new Scanner(System.in);
            String name = c.nextLine();
            for (int i = 0; i < arry1.size(); i++) {
                if (arry1.get(i).getName().equals(name)) {
                    System.out.println("--------------------------------------------"); 
                    System .out.println("Class\t\t\tName\t\tStudent Number\t\tCalculation\tEnglish\tMathematics\tPolitics");
                    System.out.println(arry1.get(i).getClassname() + "\t" + arry1.get(i).getName() + "\t\t" + arry1.get(i).getNumber() + "\t\t" + arry1.get(i).getComputer() + "\t" + arry1.get(i).getEnglish() + "\t" + arry1.get(i).getMath() + "\t" + arry1.get(i).getPolitics());
                    System.out.println("--------------------------------------------");
                }
            }
        }
    }
    //查看平均分与及格率
    public static void averagStudent(ArrayList<Student> arry1,ArrayList<Course> arry2)
    {

        for(int i=0;i<arry1.size();i++)
        {
            int flag=0;
            double l=0;
            double averag=(arry2.get(i).getComputer()+arry2.get(i).getPolitics()+arry2.get(i).getEnglish()+arry2.get(i).getMath())*1.0/4;
            if(arry2.get(i).getComputer()<60)
            {
                flag++;
            }
             if (arry2.get(i).getPolitics()<60)
             {
                 flag++;
            }
             if(arry2.get(i).getEnglish()<60)
            {
                flag++;
            }
             if(arry2.get(i).getMath()<60)
        {
            flag++;
        }
             l=(4-flag)/4.0;
            System.out.println("学号\t学生\t平均成绩\t及格率");
            System.out.println(arry1.get(i).getNumber()+"\t"+arry1.get(i).getName()+"\t"+averag+"\t"+l);
        }
    }
}

.

Guess you like

Origin blog.csdn.net/weixin_52563520/article/details/126324330