溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Java實(shí)現(xiàn)在線測評考試系統(tǒng)代碼

發(fā)布時(shí)間:2020-06-02 20:49:33 來源:億速云 閱讀:635 作者:Leah 欄目:編程語言

這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)在線測評考試系統(tǒng)的方法,文中示例代碼介紹的非常詳細(xì),零基礎(chǔ)也能參考此文章,感興趣的小伙伴們可以參考一下。

代碼展示

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("鏃犳鐢ㄦ埛!");    }    if (loginUser.getPassword().equals(Md5Utils.md5(password))) {        return loginUser;    }    throw new IdOrPasswordException("瀵嗙爜閿欒!"); } @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; }}

看完這篇文章,你們學(xué)會(huì)Java實(shí)現(xiàn)在線測評考試系統(tǒng)的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI