Home  >  Article  >  Java  >  Using Java to write the test score entry module of the online examination system

Using Java to write the test score entry module of the online examination system

PHPz
PHPzOriginal
2023-09-25 14:45:041420browse

Using Java to write the test score entry module of the online examination system

Java code implementation of the test score entry module of the online examination system

With the development of computer technology, more and more examinations have begun to be conducted online. In order to record candidates' scores conveniently and quickly, we need to develop an exam score entry module. This article will use Java language to introduce in detail the specific implementation of the test score entry module of the online examination system.

First, we need to create a grade class (Grade) to store the grade information of each candidate. The code implementation of the grade class is as follows:

public class Grade {
    private String studentName;  // 考生姓名
    private int score;  // 成绩

    public Grade(String studentName, int score) {
        this.studentName = studentName;
        this.score = score;
    }

    // 获取考生姓名
    public String getStudentName() {
        return studentName;
    }

    // 设置考生姓名
    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    // 获取成绩
    public int getScore() {
        return score;
    }

    // 设置成绩
    public void setScore(int score) {
        this.score = score;
    }
}

Next, we need to create a grade entry module class (GradeEntry) to implement the entry function of test scores. The code is implemented as follows:

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

public class GradeEntry {
    private List<Grade> gradeList;  // 考试成绩列表

    public GradeEntry() {
        gradeList = new ArrayList<>();
    }

    // 录入考试成绩
    public void enterGrade() {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入考生姓名(输入exit退出):");
        String studentName = scanner.nextLine();

        while (!studentName.equals("exit")) {
            System.out.println("请输入考生成绩:");
            int score = scanner.nextInt();

            Grade grade = new Grade(studentName, score);
            gradeList.add(grade);

            System.out.println("请输入考生姓名(输入exit退出):");
            scanner.nextLine();  // 清除缓冲区
            studentName = scanner.nextLine();
        }
    }

    // 输出考试成绩
    public void displayGrade() {
        System.out.println("考生姓名        成绩");
        for (Grade grade : gradeList) {
            System.out.println(grade.getStudentName() + "        " + grade.getScore());
        }
    }
}

Finally, we create a main class (Main) to test the score entry module. The code is implemented as follows:

public class Main {
    public static void main(String[] args) {
        GradeEntry ge = new GradeEntry();

        ge.enterGrade();  // 录入考试成绩

        System.out.println();
        ge.displayGrade();  // 输出考试成绩
    }
}

After running the main method of the main class, the system will prompt to enter the candidate's name and score. The user can enter the scores of multiple candidates until "exit" is entered to exit score entry. The system will then output the names and scores of all entered candidates.

Through the above code implementation, we can easily enter the candidates' scores in the online examination system. At the same time, we can also add more functions according to actual needs, such as score statistics, score sorting, etc. I hope this article will be helpful to everyone when developing an online examination system.

The above is the detailed content of Using Java to write the test score entry module of the online examination system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn