(1) Foreword
Because this project was written in a hurry just after learning java. Although the management system was also written in c language before, the scoring standard at that time used more data structures such as pointers and linked lists. And it is process oriented programming, not object-oriented.
This time I mainly want to write an object-oriented java student management system. The original intention is to make it an html web page version with the back-end connected to the database. As a result, the time is too tight, so I did the project implemented under eclipse. It is not very perfect. I will change it when I have time in the future. AF and RI were learned in the later software construction course, and they were not written.
Give energetic students an idea: we can set up two clients: the student client and the teacher client, set the account password respectively, and save it in sql. Then when logging in, we can judge whether ta is a teacher or a student. For teacher, we can check the results, add, delete and modify the results. For student, We can only check our grades. If necessary, add a master with higher permissions to the teacher to view the log and know which data has been changed by who.
(2) Class design
(1) Student class
The object-oriented programming idea is to write student classes. Each student has its own attributes, such as name, student number and contact number. Therefore, in the student class, these attributes should be private and include a series of set and get methods, such as setName, getName, setId, getId and so on. It also sets up two operations on the student list, add and list, that is, adding students and listing all the information of the student list.
package student; import java.util.ArrayList; import java.util.Scanner; public class Student { private String name; private String id; static ArrayList<Student> studentList=new ArrayList(); public static Scanner in = new Scanner(System.in); public Student(String name,String id)//Student information: name, student number, gender { this.name=name; this.id=id; } public void setName(String name) { this.name=name; } public String getName() { return name; } public void setId(String id) { this.id=id; } public String getId() { return id; } public static void add()//Enter student information { System.out.print("Please enter student name:"); String name = in.next(); System.out.print("Please enter student ID:"); String id = in.next(); Student student=new Student(name,id); studentList.add(student); } public static void list(ArrayList<Student> studentList)//Output information of all students { System.out.println("Student number\t full name"); for (Student student:studentList) { String name=student.getName(); String id =student.getId(); System.out.println(name+"\t"+id); } } }
(2) Course class
Originally, we wanted to set up six subjects such as physical and chemical students outside digital language as implemented in C language, but in fact, these are not the subjects in the University, so we need to leave this demand to the users themselves.
Our courselist is empty at first, that is, there are no courses. We need users to add courses themselves, including their own course name, course credits and other corresponding information. To ensure that our program has good scalability and reusability.
package student; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Course { private String name; public static ArrayList<Course> courseList = new ArrayList<>();//Save a list of course names public static Scanner in = new Scanner(System.in); public void setName(String name) { this.name = name; } public String getName() { return name; } public static void addcourse()//Add course { System.out.print("Please enter the Course Name:"); String name = in.next(); Course course=new Course(); course.setName(name); courseList.add(course); } public static void listcourse() { for(Course course:courseList) { System.out.println(course.getName()); } } }
(3) Grade class
For grade, those who want to read the first two categories will also understand that the score of each subject needs two index values to locate. Students and course s. Only when you know who you are and what subject you are, can you query your grades.
We set studentList and courseList, and gradeList takes these two parts of data as internal variables.
We need to maintain the robustness of the program, so we need to set some properties to private, and then write implementation methods such as setStudent, getStudent, setCourse, getCourse, setGrade and getGrade.
The next step is input and output, which we call input and output. The basic idea of input is to traverse the student's name, then traverse the student's course, find the corresponding score and modify it. Output is relatively simple, traversing the output.
The next step is to add, delete, modify and check four operations. Basic operation.
Average, total. Just use the operation provided by the List itself.
Then sort, enter the disciplines to be sorted, and sort them with the sort sorting method provided by list.
package student; import student.Course; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import student.Student; import student.Course; import java.util.Collections; import java.util.Comparator; public class Grade { private static Student student; private static Course course; private float grade; String stu; String cour; float gra; public static ArrayList<Grade> gradeList = new ArrayList<>(); public static List<Course> courseList = new ArrayList<>(); public static Scanner in = new Scanner(System.in); public Grade(Student student,Course course,float grade)//grade class: name, course, score { this.student=student; this.course=course; this.grade=grade; } public Grade() { } public void setStudent(Student student) { stu = student.getName(); } public String getStudent() { return stu; } public void setCourse(Course course) { cour = course.getName(); } public String getCourse() { return cour; } public void setGrade(float grade) { this.grade=grade; } public float getGrade() { return grade; } public static void input()//Enter the grade of a student in a course { float grad=0; System.out.println("Please enter student name"); String name = in.next(); for (Student student: Student.studentList) { if (student.getName().equals(name)) { System.out.println("Please enter the course name"); String coursename = in.next(); for(Course course:Course.courseList) { if(course.getName().equals(coursename)) { System.out.print("Please enter your grade:"); grad = in.nextFloat(); break; } } } } Grade grade = new Grade(); grade.setStudent(student); grade.setCourse(course); grade.setGrade(grad); gradeList.add(grade); } public static void output()//Print students' grades of a course { System.out.println("full name\t curriculum\t achievement"); for(Grade grade:gradeList) { String student =grade.getStudent(); String course=grade.getCourse(); float gra=grade.getGrade(); System.out.println("\t"+student+"\t"+course+"\t"+gra); } } public static void change() { System.out.println("Please enter the name of the student to be modified"); String name = in.next(); for(Grade grade:gradeList) { if(name.equals(grade.getStudent())) { System.out.println("Please enter the account to modify"); String course=in.next(); if(course.equals(grade.getCourse())) { System.out.println("Please enter the score to modify"); float gra = in.nextFloat(); grade.setGrade(gra); break; } } } } public static void search() { System.out.println("Please enter the name of the student you want to find"); String name = in.next(); System.out.println("\t full name\t curriculum\t achievement"); for (Grade grade:gradeList) { if(grade.getStudent().equals(name)) { System.out.println("\t"+grade.getStudent()+"\t"+grade.getCourse()+"\t"+grade.getGrade()); } } } public static void remove() { System.out.println("Please enter the name of the student to delete"); String name =in.next(); for (Grade grade:gradeList) { if(name.equals(grade.getStudent())) { gradeList.remove(grade); } } } public static float sum() { float sum=0; for(Grade grade:gradeList) { sum+=grade.grade; } return sum; } public static float average() { float sum=0; for(Grade grade:gradeList) { sum+=grade.grade; } return sum/gradeList.size(); } public void sort() { System.out.println("Please enter the subject to be ranked"); } }
(4) Menu class
There are several sections that users can choose when running the program.
a.studentmenu
If you choose 1, you will enter the studentmenu.
We have the following items to add students, display student information, return to the previous level and exit the system. The specific functions have been written. You can play by yourself if you want to play.
b.coursemenu
c.grademenu
package student; import java.util.Scanner; public class Menu { public static Scanner in = new Scanner (System.in); public static void main(String[] args) { mainmenu(); } public static void mainmenu() { System.out.println("\t\t\t Student achievement management system of Harbin Institute of Technology"); System.out.println("\t\t\t1.Student information"); System.out.println("\t\t\t2.Course information"); System.out.println("\t\t\t3.Achievement information"); System.out.println("\t\t\t4.Operation guide"); System.out.println("\t\t\t0.Exit the system"); System.out.println("\t\t\t Please enter:"); int i=in.nextInt(); switch(i) { case 1: studentmenu(); break; case 2: coursemenu(); break; case 3: grademenu(); break; case 4: System.out.println("1.Enter student information, including name and student number"+"\n"+"2.Enter course information, including course name"); break; case 0: System.out.println("You have exited"); System.exit(0); break; default: System.out.println("You have entered illegal characters"); break; } } public static void studentmenu() { for(;;) { System.out.println("\t\t\t1.Add student"); System.out.println("\t\t\t2.Display student information"); System.out.println("\t\t\t3.Return to the previous level"); System.out.println("\t\t\t0.Exit the system"); System.out.println("\t\t\t Please enter:"); int i = in.nextInt(); switch(i) { case 1: Student.add(); break; case 2: Student.list(Student.studentList); break; case 3: mainmenu(); break; case 0: System.out.println("You have exited"); System.exit(0); break; default: System.out.println("You have entered illegal characters"); studentmenu(); } System.out.println("Please continue:"); } } public static void coursemenu() { for(;;) { System.out.println("\t\t\t1.Add course"); System.out.println("\t\t\t2.Show course information"); System.out.println("\t\t\t3.Return to the previous level"); System.out.println("\t\t\t0.Exit the system"); System.out.println("\t\t\t Please enter:"); int i = in.nextInt(); switch(i) { case 1: Course.addcourse(); break; case 2: Course.listcourse(); break; case 3: mainmenu(); break; case 0: System.out.println("You have exited"); System.exit(0); break; default: System.out.println("You have entered illegal characters"); coursemenu(); } System.out.println("Please continue:"); } } public static void grademenu() { for(;;) { System.out.println("\t\t\t1.Enter student grade"); System.out.println("\t\t\t2.Print student grades"); System.out.println("\t\t\t3.Modify student grades"); System.out.println("\t\t\t4.Query student scores"); System.out.println("\t\t\t5.Delete student"); System.out.println("\t\t\t6.Total score and average score"); System.out.println("\t\t\t7.Score ranking"); System.out.println("\t\t\t8.Return to the previous level"); System.out.println("\t\t\t0.Exit the system"); System.out.println("\t\t\t Please enter:"); int i =in.nextInt(); switch(i) { case 1: Grade.input(); break; case 2: Grade.output(); break; case 3: Grade.change(); break; case 4: Grade.search(); break; case 5: Grade.remove(); break; case 6: System.out.println("Do you want to know the total score or average score"); System.out.println("1.Total score 2.average"); int iq=in.nextInt(); System.out.println("emm Let me tell you"); System.out.println("Total score\t\t average"); System.out.println(Grade.sum()+"\t\t"+Grade.average()); break; case 7: break; case 8: mainmenu(); break; case 0: System.out.println("You have exited"); System.exit(0); break; } } } }
(3) Summary
In fact, there is no special idea. For a relatively simple management system, many ideas have not been realized due to time reasons. After that, it may be changed again, but it is estimated that it has been greatly changed. In fact, it can only be the level of big homework.