Java project: online test system

Java small project: online evaluation test system, so that you can take a test at home!
Today's java small project is a set of online evaluation examination system, and the question bank is subject one. You can not only practice Java technology at home, but also learn subjects at the same time, kill two birds with one stone.
Introduction to the interface: start, score, examination rules, leave, four options.
There are a lot of question banks to choose from. You can send me a private message!
Code display:
package service;

import java.util.ArrayList;

import java.util.List;

import java.util.Random;

import util.Config;
import util.Md5Utils;
import entity.EntityContext;
import entity.ExamInfo;
import entity.Question;
import entity.QuestionInfo;
import entity.User;
import exception.IdOrPasswordException;

public class ExamServiceImpl implements ExamService {
private EntityContext entityContext;
private List<QuestionInfo> paper = new ArrayList<QuestionInfo>();
private Config config;
private User loginUser;

public List<QuestionInfo> getPaper() {
    return paper;
}

public void setPaper(List<QuestionInfo> paper) {
    this.paper = paper;
}

public ExamServiceImpl(EntityContext entityContext, Config config) {
    super();
    this.entityContext = entityContext;
    this.config = config;
}

public ExamServiceImpl(EntityContext entityContext) {
    super();
    this.entityContext = entityContext;
}

@Override
public User login(int id, String password) throws IdOrPasswordException {
    loginUser = entityContext.findUserById(id);
    if (loginUser == null) {
        throw new IdOrPasswordException("Chinese styleA kind ofㄦA kind of!");
    }
    if (loginUser.getPassword().equals(Md5Utils.md5(password))) {
        return loginUser;
    }
    throw new IdOrPasswordException("Password key!");
}

@Override
public ExamInfo start() {
    buildPaper();
    ExamInfo examInfo = new ExamInfo();
    examInfo.setUser(loginUser);
    examInfo.setTimeLimit(config.getInt("TimeLimit"));
    examInfo.setExamTitle(config.getString("PaperTitle"));
    examInfo.setQuestionNumber(config.getInt("QuestionNumber"));
    return examInfo;
}

private void buildPaper() {
    int i = 0;
    Random random = new Random();
    for (int level = Question.LEVEL1; level <= Question.LEVEL10; level++) {
        List<Question> list = entityContext.getQuestions(level);
        Question q1 = list.remove(random.nextInt(list.size()));
        Question q2 = list.remove(random.nextInt(list.size()));
        paper.add(new QuestionInfo(++i, q1));
        paper.add(new QuestionInfo(++i, q2));
    }

}

@Override
public QuestionInfo getQuestionInfo(int index) {
    return paper.get(index - 1);
}

@Override
public void sendUserAnswers(int questionIndex, List<Integer> answers) {
    QuestionInfo questionInfo = paper.get(questionIndex - 1);
    questionInfo.setUserAnswers(new ArrayList<Integer>(answers));
}

@Override
public int getTotalSocre() {
    int score = 0;
    for (QuestionInfo questionInfo : paper) {
        if (questionInfo.getUserAnswers().equals(
                questionInfo.getQuestion().getAnswers())) {
            score += questionInfo.getQuestion().getScore();
        }
    }
    return score;
}

}
Like this article can pay attention to me, I will continue to update, your attention is my update power! Need more java Science

You can also trust me!

I wish all the people who pay attention to me: good health, rich financial resources, good fortune like the East China Sea, long life than Nanshan Mountain, having a baby early and never losing their hair!

Tags: Java

Posted on Tue, 04 Feb 2020 09:03:35 -0800 by Piranha