栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

采用Java编写一个软件,100以内的口算题,加减运算,运算结果位于[0,100]区间内,要求自动生成题库,实现自动判分,自动生成成绩,并且有图形化CUI界面

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

采用Java编写一个软件,100以内的口算题,加减运算,运算结果位于[0,100]区间内,要求自动生成题库,实现自动判分,自动生成成绩,并且有图形化CUI界面

这是我们软件构造实验课的内容,就简单做了这么一个实验,话不多说直接上效果,是基于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";
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/353515.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号