这是我们软件构造实验课的内容,就简单做了这么一个实验,话不多说直接上效果,是基于springboot实现的
可以轻松算出你的错题,并且整理错题(正确题目不会出现);
为了演示,只输入了一部分
关键代码如下:
package com.lrl.question.util;
import com.lrl.question.vo.Question;
import com.lrl.question.vo.Problem;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@Configuration
public class QuestionUtil {
@Bean
public Problem getQuestion() {
ListquestionList = new ArrayList<>();
Integer result[] = new Integer[50];
Problem problem = new Problem();
int m = 0, n = 0, value = 0;
char o = '+';
Random random = new Random();
int ov = random.nextInt(2); // 0:加号; 1:减号
for (int i = 0; i < 50; i++) {
if(ov == 0) {
o = '+';
do {
m = random.nextInt(101);
n = random.nextInt(101);
value = m + n;
}while(value > 100);
}else {
o = '-';
do {
m = random.nextInt(101);
n = random.nextInt(101);
value = m - n;
}while(value < 0);
}
ov = random.nextInt(2);
Question question = new Question();
String que = "";
question.setQuestion("" + m + o + n + " = ");
question.setNum(i+1);
questionList.add(question);
result[i] = value;
}
problem.setResult(result);
problem.setList(questionList);
return problem;
}
}
@Controller
public class QuestionController {
@Autowired
private Problem getQuestion;
@GetMapping("/")
public String toQuestion(Model model){
List questionList = getQuestion.getList();
model.addAttribute("questionList",questionList);
return "question";
}
@PostMapping("/score")
private String getGrade(Model model,Integer value[]){
ListmistakeList = new ArrayList<>();
Integer score = 100;
Integer result[] = value;
Integer answer[] = getQuestion.getResult();
for (int i = 0; i < getQuestion.getList().size(); i++) {
if(result[i]!=answer[i]){
score = score-2;
Mistake mistake = new Mistake();
mistake.setMistake(getQuestion.getList().get(i).getQuestion());
mistake.setMistakeNum(i+1);
mistake.setMistakeResult(result[i]);
mistake.setCorrectResult(answer[i]);
mistakeList.add(mistake);
}
}
model.addAttribute("score",score);
model.addAttribute("mistakeList",mistakeList);
return "score";
}
}


![采用Java编写一个软件,100以内的口算题,加减运算,运算结果位于[0,100]区间内,要求自动生成题库,实现自动判分,自动生成成绩,并且有图形化CUI界面 采用Java编写一个软件,100以内的口算题,加减运算,运算结果位于[0,100]区间内,要求自动生成题库,实现自动判分,自动生成成绩,并且有图形化CUI界面](http://www.mshxw.com/aiimages/31/353515.png)
