Java小项目之:在线测评考试系统,让你可以在家考科一!

Java小项目之:在线测评考试系统,让你可以在家考科一!

今天带来的java小项目是一套在线测评考试系统,题库是科目一的。不仅可以在家练练java技术,还可以边学习学习科目一,一举两得。

界面介绍:开始、分数、考试规则、离开,四个选项。

还有很多题库可以选择,可以私信我!

代码展示:

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;

}

 

}

喜欢这样文章的可以关注我,我会持续更新,你们的关注是我更新的动力!需要更多java学习资料的也可以私信我!

 

祝关注我的人都:身体健康,财源广进,福如东海,寿比南山,早生贵子,从不掉发!

 

上一篇:论文查重


下一篇:Paper代写:别让段落结尾拉低你的分数