這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)在線測(cè)評(píng)考試系統(tǒng)的方法,文中示例代碼介紹的非常詳細(xì),零基礎(chǔ)也能參考此文章,感興趣的小伙伴們可以參考一下。
創(chuàng)新互聯(lián)主營(yíng)湘潭網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都App制作,湘潭h5微信小程序開(kāi)發(fā)搭建,湘潭網(wǎng)站營(yíng)銷推廣歡迎湘潭等地區(qū)企業(yè)咨詢
代碼展示
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)在線測(cè)評(píng)考試系統(tǒng)的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
本文標(biāo)題:Java實(shí)現(xiàn)在線測(cè)評(píng)考試系統(tǒng)代碼
當(dāng)前路徑:http://jinyejixie.com/article12/psipdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、企業(yè)建站、網(wǎng)站排名、Google、域名注冊(cè)、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)