Design and implementation of online examination system

1. Design background

Recently, some users have put forward the need to implement a set of video learning module and online examination module in the original website. Here, I will first introduce the design idea of the following online examination module.

To realize an online examination system with basic functions, the following elements are required:

1. Question bank management [it may be necessary to design different question banks for different examinations, such as driving test subject 1 and road transportation Qualification Certificate]

2. Chapter management [corresponding to the chapter of examination and training materials]

3. Examination question management [all examination questions contained in the question bank]

4. Test options [options for each question]

5. Exact answer [exact answer to each question]

6. Examination management [publish the latest examination connection on the website, and users can enter the examination through the link]

7. Check the examination results [check the examination results and wrong questions in real time after completing the examination] after realizing the above functions, it is basically a relatively complete examination system. Next, we design the table structure for these function points.

2. Table structure design

According to the above detailed contents, we first design the following database, which is mapped directly here, and the notes are written clearly

3. Implementation process of some functions and key code fragments

The code is also written in a mess, and there is no emphasis on too many small functions. Let's make do with it.

Introduction to architecture environment: the whole is based on jfinal_cms development, based on jfinal, mvc framework, the template engine is beetl, and the foreground is still the traditional bootstrap and jquery

If you feel that your learning efficiency is low and you lack correct guidance, you can join the technology circle with rich resources and strong learning atmosphere to learn and communicate together!
[Java architecture group]
There are many technological giants from the front line in the group, as well as code farmers struggling in small factories or outsourcing companies. We are committed to building an equal and high-quality JAVA Communication circle, which may not make everyone's technology advance by leaps and bounds in the short term, but in the long run, vision, pattern and long-term development direction are the most important.

3.1 question bank management

It's simple here. There's no logic

3.2 topic management

The following is the code for setting the correct options. Here, the processing logic of multiple topics is added separately. The IDs of the accurate options are separated by commas and saved after splicing

 private void  set_right(TbExamAnswer model,TbExamQuestions questionsModel) {
		if(questionsModel.getQuestionsType()!=111) {//Accurate answer setting of single choice and judgment questions
			questionsModel.setRightAnswerId(model.getId().toString());
			questionsModel.setRightAnswerTitle(model.getAnswerTitle());
		}else {
			List<TbExamAnswer> answerList=TbExamAnswer.dao.findByWhere(" where questions_id=? and answer_right=1 order by id asc",questionsModel.getId());
			StringBuffer right_ids=new StringBuffer("");
			StringBuffer right_title=new StringBuffer("");
			for(int i=0;i<answerList.size();i++) {
				TbExamAnswer answer=answerList.get(i);
				right_ids.append(answer.getId().toString());
				right_title.append(answer.getAnswerTitle());
				if(i<answerList.size()-1) {
					right_ids.append(",");
					right_title.append(",");				
				}
			}
			questionsModel.setRightAnswerId(right_ids.toString());
			questionsModel.setRightAnswerTitle(right_title.toString());
		}
		questionsModel.update();
	} 

3.3 examination release

Here is the front page after the examination is released. Users can enter the examination page through this connection

The total number of basic information questions field needs to be set in the test release operation to control the number of questions drawn in each user's answer paper. The number of questions drawn in each chapter needs to be set in the rules. The following is the code of the question drawing part.

 public void index() {
		// Data list
		SysUser user = (SysUser) getSessionUser();
		if (user == null) {
			redirect(CommonController.firstPage);
			return;
		}
		int examPublishId = getParaToInt();
		TbExamPublish examPublish=TbExamPublish.dao.findById(examPublishId);
		TbExamPaper paper=new TbExamPaper();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar nowTime=Calendar.getInstance();
		if(examPublish.getExamTimeLength()==null) {
			nowTime.add(Calendar.MINUTE, 60);
		}else {
			nowTime.add(Calendar.MINUTE, examPublish.getExamTimeLength());
		}

		paper.setUserId(user.getUserid());//User id
		paper.setUserName(user.getUserName());//User name
		paper.setExamPublishId(examPublish.getId());//Exam release id
		paper.setExamName(examPublish.getExamName());
		paper.setExamCode(examPublish.getExamCode());//Examination number
		paper.setExamStatus(1);//In the exam
		paper.setExamStartDate(sdf.format(new Date()));
		paper.setExamEndDate(sdf.format(nowTime.getTime()));
		paper.save();
		
		List<TbExamPublishRule> ruleList =TbExamPublishRule.dao.findByWhere(" where exam_publish_id="+examPublish.getId());
		String questionWhere="tb_exam_questions where tk_id=? and chapter_id=? and questions_type=? ORDER BY RAND() LIMIT ?";
		for(int i=0;i<ruleList.size();i++) {
			TbExamPublishRule rule=ruleList.get(i);
			List<TbExamQuestions> singleChoiceQuestions=TbExamQuestions.dao.findByWhere(questionWhere, rule.getExamTkId(),rule.getExamChapterId(),109,rule.getSingleChoiceCount());//Extract single choice questions
			List<TbExamQuestions> multipleChoiceQuestions=TbExamQuestions.dao.findByWhere(questionWhere, rule.getExamTkId(),rule.getExamChapterId(),111,rule.getMultipleChoiceCount());//Extract multiple topics
			List<TbExamQuestions> judgeQuestions=TbExamQuestions.dao.findByWhere(questionWhere, rule.getExamTkId(),rule.getExamChapterId(),110,rule.getJudgeCount());//Extract judgment questions
			singleChoiceQuestions.addAll(multipleChoiceQuestions);//Merge single and multiple selection list s
			for(TbExamQuestions q:singleChoiceQuestions) {
				TbExamPaperQuestions paperQuestion=new TbExamPaperQuestions();
				paperQuestion.setPaperId(paper.getId());//Test paper id
				paperQuestion.setQuestionsId(q.getId());//Title id
				paperQuestion.setQuestionsTitle(q.getQuestionsTitle());//subject
				paperQuestion.setQuestionsType(q.getQuestionsType());//Topic type
				paperQuestion.setRightAnswerId(q.getRightAnswerId());//Exact option id
				paperQuestion.setRightAnswerTitle(q.getRightAnswerTitle());//Exact option title
				paperQuestion.save();
				List<TbExamAnswer> answers=TbExamAnswer.dao.findByWhere(" where questions_id=? order by id asc", q.getId());//Query options list
				for(TbExamAnswer a:answers) {
					TbExamPaperAnswer paperAnswer=new TbExamPaperAnswer();
					paperAnswer.setPaperId(paper.getId());//Test paper id
					paperAnswer.setQuestionsId(q.getId());//Title id
					paperAnswer.setAnswerId(a.getId().toString());//Option id
					paperAnswer.setAnswerTitle(a.getAnswerTitle());//Option title
					paperAnswer.setAnswerContent(a.getAnswerContent());//Option content
					paperAnswer.setAnswerRight(a.getAnswerRight()==null?null:a.getAnswerRight().toString());//Is the correct answer
					paperAnswer.save();
				}
			}
			
			for(TbExamQuestions q:judgeQuestions) {
				TbExamPaperQuestions paperQuestion=new TbExamPaperQuestions();
				paperQuestion.setPaperId(paper.getId());//Test paper id
				paperQuestion.setQuestionsId(q.getId());//Title id
				paperQuestion.setQuestionsTitle(q.getQuestionsTitle());//subject
				paperQuestion.setQuestionsType(q.getQuestionsType());//Topic type
				paperQuestion.setRightAnswerId(q.getRightAnswerId());//Exact option id
				paperQuestion.setRightAnswerTitle(q.getRightAnswerTitle());//Exact option title
				paperQuestion.save();
			}
				//BeanUtils.copyProperties(q,choiceQuestions.get(0));
			//log.info(rule.getExamChapterName() + "multiple choice questions --" + choicequestions Size () + "judgment question --" + judgequestions size());
		}
		redirect("/front/onlineExam/toExam/"+paper.getId());
		return;
	}

	public void toExam() {
		log.info("Start the exam");
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat sdf1=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		int paperId = getParaToInt();
		TbExamPaper paper=TbExamPaper.dao.findById(paperId);//Test paper entity
		List<TbExamPaperQuestions> questionsList=TbExamPaperQuestions.dao.findByWhere(" where paper_id=? order by questions_type desc", paperId);//Query title list
		Map<Integer,List<TbExamPaperAnswer>> answerMap=new HashMap<Integer,List<TbExamPaperAnswer>>();//Item map
		for(TbExamPaperQuestions q:questionsList) {
			List<TbExamPaperAnswer> answers=TbExamPaperAnswer.dao.findByWhere(" where paper_id=? and questions_id=?", paperId,q.getQuestionsId());
			answerMap.put(q.getQuestionsId(), answers);
		}
		//try {
		Date d=paper.getExamEndDate();
		setAttr("examEndDate",sdf1.format(d));
		setAttr("paper",paper);
		setAttr("questionsList",questionsList);
		setAttr("answerMap",answerMap);
		renderAuto(path + "exam_page.html");
	} 

The following is the test page. The implementation method is mainly to traverse all the test questions, and render different dom tags according to the question type.

![image.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/84ccf4e896324bccae9382d0dc8775ca~tplv-k3u1fbpfcp-watermark.image)

This js method is mainly to save the answer data in real time during the answer process to prevent the loss of data when the page is refreshed

 function commitAnswer(paperId,questionsId,questionsType,answerId,domName){
			if(questionsType==111){
				var selAnswerId="";
				$("input:checkbox[name='"+domName+"']:checked").each(function(index) { // Traverse the multiple selection box of name=test
					size=$("input:checkbox[name='"+domName+"']:checked").length;
					if(index==size-1){
						selAnswerId+=$(this).val();  // Value of each selected item
					}else{
						selAnswerId+=$(this).val()+",";  // Value of each selected item 
					}
				});
				answerId=selAnswerId;
			}
			var url = '${BASE_PATH }front/onlineExam/saveAnswer';
			$.ajax({
				type:'POST',
				dataType:'json',
				data:{
					"paperId":paperId,
					"questionsId":questionsId,
					"questionsType":questionsType,
					"answerId":answerId
				},
				url:url,
				success:function(data){
					//$("#chapter_id").empty();
					//for(var i=0;i<data.length;i++){
					//	var item=data[i];
				  //  $("#chapter_id").append("<option value='"+item.id+"'>"+item.chapterName+"</option>");
					//}
					
				},
				error:function(html){
				}
			});
		} 

This code is the method to calculate the score after confirming the submission. The logic is very simple. You can compare the answer options with the accurate answer options

 public void commitPaper() {
		int paperId = getParaToInt();
		int score=0;
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		TbExamPaper paper=TbExamPaper.dao.findById(paperId);//Test paper entity
		List<TbExamPaperQuestions> list=TbExamPaperQuestions.dao.findByWhere(" where paper_id=?",paperId);
		for(int i=0;i<list.size();i++) {
			TbExamPaperQuestions q=list.get(i);
			if(q.getRightAnswerId()==null)continue;
			if(q.getRightAnswerId().equals(q.getUserAnswerId()))score++;
		}
		
		int examTimeLength=getBetweenMinutes(paper.getExamStartDate(),new Date());
		paper.setExamScore(score);
		paper.setExamTimeLength(examTimeLength);
		paper.setExamEndDate(sdf.format(new Date()));
		paper.setExamStatus(-1);//Set to submission status
		paper.update();
		log.info("Total score"+score);
		redirect("/front/onlineExam/viewPaperResult/"+paper.getId());
	} 

Here is the test result page, which can display the correct and wrong questions

Here is the page for the administrator to view the examination list, which can improve the screening conditions or other personality functions. Here, only the query function is realized

So far, we have basically completed a complete set of online examination system, but there are many problems in the design idea and code implementation. Here we can throw a brick to attract jade. If you have better ideas, you can also communicate together in the comment area.

last

Fan benefits: the following are the interview questions that must be asked in the development of Java interview for more than 1-5 years. They are also the necessary skills for Java interview of front-line Internet companies. The following is the skill chart required by Alibaba's annual salary of 50W. You can refer to it!

At the same time, for these 12 skills, I sorted out a special PDF document for advanced interview of Java architecture here (including 450 question analysis, including analysis of knowledge points such as Dubbo, Redis, Netty, zookeeper, Spring cloud, distributed, high concurrency, design mode, MySQL, rich content and combination of graphics and text!)


This special document is free to share. Friends in need can look below to get it!!

If you need a full version of the document, you can click three times and get the free way below!

Keywords: Java Programming Database Big Data

Added by godwisam on Tue, 01 Feb 2022 03:30:42 +0200