Using Java to implement the test paper score query function of the online examination system
With the continuous development of network technology, more and more examination occasions have begun to use online examination systems. The online examination system facilitates candidates' registration, examination and score inquiry. This article will use Java to write a simple test paper score query function in an online examination system, and provide specific code examples.
First, we need to create a student class to save information such as students' names and grades.
public class Student { private String name; private double score; public Student(String name, double score) { this.name = name; this.score = score; } public String getName() { return name; } public double getScore() { return score; } }
Next, we need to create a test paper class for operations such as saving students' answers and calculating scores.
public class ExamPaper { private List<Student> students; public ExamPaper() { students = new ArrayList<>(); } public void addStudent(Student student) { students.add(student); } public double getStudentScore(String name) { for (Student student : students) { if (student.getName().equals(name)) { return student.getScore(); } } return -1; } }
In the main function, we can create a test paper object and add student and grade information. Then, query the corresponding grades by entering the student's name.
public class Main { public static void main(String[] args) { ExamPaper examPaper = new ExamPaper(); examPaper.addStudent(new Student("张三", 90)); examPaper.addStudent(new Student("李四", 85)); examPaper.addStudent(new Student("王五", 95)); Scanner scanner = new Scanner(System.in); System.out.print("请输入学生姓名:"); String name = scanner.nextLine(); double score = examPaper.getStudentScore(name); if (score == -1) { System.out.println("未找到该学生的成绩!"); } else { System.out.println("学生" + name + "的成绩为:" + score); } } }
The above is the Java implementation of the test paper score query function of a simple online examination system. By creating the student class and test paper class, and adding student and grade information in the main function, we can easily query the corresponding grades by entering the student's name. Of course, this is just a simple example, and it can be further expanded and optimized according to needs in actual use.
The test paper score query function of the online examination system is one of the important modules. Through the object-oriented features of Java and the use of collection classes, we can easily implement this function and manage and query the score data. I hope the code examples in this article can help readers better understand and apply Java programming technology.
The above is the detailed content of Using Java to implement the test paper score query function of the online examination system. For more information, please follow other related articles on the PHP Chinese website!