自动生成数学题型二(框架struts2)题型如((a+b)*c=d)
1. 生成题目
1.1 生成单个题目
1 public static String[] twoOperatorAndOperator(int num1, int num2) { 2 double first = generate(num1, num2); 3 double secound = generate(num1, num2); 4 double third = generate(num1, num2); 5 System.out.println(num1+" num1"); 6 System.out.println(num2+" num2"); 7 int zero = 0; 8 zero=generate(1, 28); 9 System.out.println(zero + " zero"); 10 switch (zero) { 11 case 1: 12 double result = first + secound + third; 13 String[] addAndAdd = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 14 String.format("%.0f", third), String.format("%.0f", result), String.valueOf(1), "+", "+", null, 15 null, null, null }; 16 return addAndAdd; 17 case 2: 18 if (first + secound >= third) { 19 double result2 = first + secound - third; 20 String[] addAndSub = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 21 String.format("%.0f", third), String.format("%.0f", result2), String.valueOf(2), "+", "-", null, 22 null, null, null }; 23 return addAndSub; 24 } else { 25 double result2 = third + secound - first; 26 String[] addAndSub = new String[] { String.format("%.0f", third), String.format("%.0f", secound), 27 String.format("%.0f", first), String.format("%.0f", result2), String.valueOf(2), "+", "-", null, 28 null, null, null }; 29 return addAndSub; 30 } 31 case 3: 32 double result3 = first + secound * third; 33 String[] addAndMul = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 34 String.format("%.0f", third), String.format("%.0f", result3), String.valueOf(3), "+", "*", null, 35 null, null, null }; 36 return addAndMul; 37 case 4: 38 if (third != 0) { 39 double result4 = first + secound / third; 40 String[] addAndDiv = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 41 String.format("%.0f", third), String.format("%.2f", result4), String.valueOf(4), "+", "/", null, 42 null, null, null }; 43 return addAndDiv; 44 } else { 45 twoOperatorAndOperator(num1, num2); 46 } 47 case 5: 48 if (first - secound + third >= 0) { 49 double result5 = first - secound + third; 50 String[] SubAndAdd = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 51 String.format("%.0f", third), String.format("%.0f", result5), String.valueOf(5), "-", "+", null, 52 null, null, null }; 53 return SubAndAdd; 54 } else { 55 double result5 = secound - first - third; 56 String[] SubAndAdd = new String[] { String.format("%.0f", secound), String.format("%.0f", first), 57 String.format("%.0f", third), String.format("%.0f", result5), String.valueOf(5), "-", "-", null, 58 null, null, null }; 59 return SubAndAdd; 60 } 61 case 6: 62 if (first - secound - third >= 0) { 63 double result6 = first - secound - third; 64 String[] SubAndSub = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 65 String.format("%.0f", third), String.format("%.0f", result6), String.valueOf(6), "-", "-", null, 66 null, null, null }; 67 return SubAndSub; 68 } else { 69 double result6 = third + secound - first; 70 String[] SubAndSub = new String[] { String.format("%.0f", third), String.format("%.0f", secound), 71 String.format("%.0f", first), String.format("%.0f", result6), String.valueOf(6), "+", "-", null, 72 null, null, null }; 73 return SubAndSub; 74 } 75 case 7: 76 if (first - secound * third > 0) { 77 double result7 = first - secound * third; 78 String[] SubAndMul = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 79 String.format("%.0f", third), String.format("%.0f", result7), String.valueOf(7), "-", "*", null, 80 null, null, null }; 81 return SubAndMul; 82 } else { 83 double result7 = third * secound - first; 84 String[] SubAndMul = new String[] { String.format("%.0f", third), String.format("%.0f", secound), 85 String.format("%.0f", first), String.format("%.0f", result7), String.valueOf(7), "*", "-", null, 86 null, null, null }; 87 return SubAndMul; 88 } 89 90 case 8: 91 if (third != 0) { 92 if (first - secound / third > 0) { 93 double result8 = first - secound / third; 94 String[] SubAndDiv = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 95 String.format("%.0f", third), String.format("%.2f", result8), String.valueOf(8), "-", "/", 96 null, null, null, null }; 97 return SubAndDiv; 98 } else { 99 double result8 = secound / third - first; 100 String[] SubAndDiv = new String[] { String.format("%.0f", secound), String.format("%.0f", third), 101 String.format("%.0f", first), String.format("%.2f", result8), String.valueOf(8), "/", "-", 102 null, null, null, null }; 103 return SubAndDiv; 104 } 105 } else { 106 twoOperatorAndOperator(num1, num2); 107 } 108 case 9: 109 double result9 = first * secound + third; 110 String[] MulAndAdd = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 111 String.format("%.0f", third), String.format("%.0f", result9), String.valueOf(9), "*", "+", null, 112 null, null, null }; 113 return MulAndAdd; 114 case 10: 115 if (first * secound - third > 0) { 116 double result10 = first * secound - third; 117 String[] MulAndSub = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 118 String.format("%.0f", third), String.format("%.0f", result10), String.valueOf(10), "*", "-", 119 null, null, null, null }; 120 return MulAndSub; 121 } else { 122 double result10 = third - first * secound; 123 String[] MulAndSub = new String[] { String.format("%.0f", third), String.format("%.0f", first), 124 String.format("%.0f", secound), String.format("%.0f", result10), String.valueOf(10), "-", "*", 125 null, null, null, null }; 126 return MulAndSub; 127 } 128 129 case 11: 130 double result11 = first * secound * third; 131 String[] MulAndMul = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 132 String.format("%.0f", third), String.format("%.0f", result11), String.valueOf(11), "*", "*", null, 133 null, null, null }; 134 return MulAndMul; 135 case 12: 136 if (third != 0) { 137 double result12 = first * secound / third; 138 String[] MulAndDiv = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 139 String.format("%.0f", third), String.format("%.2f", result12), String.valueOf(12), "*", "/", 140 null, null, null, null }; 141 return MulAndDiv; 142 } else { 143 twoOperatorAndOperator(num1, num2); 144 } 145 case 13: 146 if (secound != 0) { 147 double result13 = first / secound + third; 148 String[] DivAndAdd = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 149 String.format("%.0f", third), String.format("%.2f", result13), String.valueOf(13), "/", "+", 150 null, null, null, null }; 151 return DivAndAdd; 152 } else { 153 twoOperatorAndOperator(num1, num2); 154 } 155 case 14: 156 if (secound > 0) { 157 if (first / secound - third > 0) { 158 double result14 = first / secound - third; 159 String[] DivAndSub = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 160 String.format("%.0f", third), String.format("%.2f", result14), String.valueOf(14), "/", "-", 161 null, null, null, null }; 162 return DivAndSub; 163 } else { 164 double result14 = third - first / secound; 165 String[] DivAndSub = new String[] { String.format("%.0f", third), String.format("%.0f", first), 166 String.format("%.0f", secound), String.format("%.2f", result14), String.valueOf(14), "-", 167 "/", null, null, null, null }; 168 return DivAndSub; 169 } 170 } else { 171 twoOperatorAndOperator(num1, num2); 172 } 173 case 15: 174 if (secound != 0) { 175 double result15 = first / secound * third; 176 String[] DivAndMul = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 177 String.format("%.0f", third), String.format("%.2f", result15), String.valueOf(15), "/", "*", 178 null, null, null, null }; 179 return DivAndMul; 180 } else { 181 twoOperatorAndOperator(num1, num2); 182 } 183 case 16: 184 if (secound != 0 && third != 0) { 185 double result16 = first / secound / third; 186 String[] DivAndDiv = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 187 String.format("%.0f", third), String.format("%.2f", result16), String.valueOf(16), "/", "/", 188 null, null, null, null }; 189 return DivAndDiv; 190 } else { 191 twoOperatorAndOperator(num1, num2); 192 } 193 case 17: 194 double result17 = (first + secound) * third; 195 String[] AddAndMul2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 196 String.format("%.0f", third), String.format("%.0f", result17), String.valueOf(17), "+", "*", "(", 197 null, ")", null }; 198 return AddAndMul2; 199 case 18: 200 if (third != 0) { 201 double result18 = (first + secound) / third; 202 String[] AddAndDiv2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 203 String.format("%.0f", third), String.format("%.2f", result18), String.valueOf(18), "+", "/", 204 "(", null, ")", null }; 205 return AddAndDiv2; 206 } else { 207 twoOperatorAndOperator(num1, num2); 208 } 209 case 19: 210 if (first > secound) { 211 double result19 = (first - secound) * third; 212 String[] SubAndMul2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 213 String.format("%.0f", third), String.format("%.0f", result19), String.valueOf(19), "-", "*", 214 "(", null, ")", null }; 215 return SubAndMul2; 216 } else { 217 double result19 = (secound - first) * third; 218 String[] SubAndMul2 = new String[] { String.format("%.0f", secound), String.format("%.0f", first), 219 String.format("%.0f", third), String.format("%.0f", result19), String.valueOf(19), "-", "*", 220 "(", null, ")", null }; 221 return SubAndMul2; 222 } 223 case 20: 224 if (third != 0) { 225 double result20 = (first + secound) / third; 226 String[] SubAndDiv2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 227 String.format("%.0f", third), String.format("%.2f", result20), String.valueOf(20), "+", "/", 228 "(", null, ")", null }; 229 return SubAndDiv2; 230 } else { 231 twoOperatorAndOperator(num1, num2); 232 } 233 case 21: 234 double result21 = first * (secound + third); 235 String[] MulAndAdd2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 236 String.format("%.0f", third), String.format("%.0f", result21), String.valueOf(21), "*", "+", null, 237 "(", null, ")" }; 238 return MulAndAdd2; 239 case 22: 240 if (secound > third) { 241 double result22 = first * (secound - third); 242 String[] MulAndSub2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 243 String.format("%.0f", third), String.format("%.2f", result22), String.valueOf(22), "*", "-", 244 null, "(", null, ")" }; 245 return MulAndSub2; 246 } else { 247 double result22 = first * (third - secound); 248 String[] MulAndSub2 = new String[] { String.format("%.0f", first), String.format("%.0f", third), 249 String.format("%.0f", secound), String.format("%.2f", result22), String.valueOf(22), "*", "-", 250 null, "(", null, ")" }; 251 return MulAndSub2; 252 } 253 case 23: 254 if ((secound + third) != 0) { 255 double result23 = first / (secound + third); 256 String[] DivAndAdd2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 257 String.format("%.0f", third), String.format("%.2f", result23), String.valueOf(23), "/", "+", 258 null, "(", null, ")" }; 259 return DivAndAdd2; 260 } else { 261 twoOperatorAndOperator(num1, num2); 262 } 263 case 24: 264 if (secound > third) { 265 double result24 = first / (secound - third); 266 String[] DivAndSub2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 267 String.format("%.0f", third), String.format("%.2f", result24), String.valueOf(24), "/", "-", 268 null, "(", null, ")" }; 269 return DivAndSub2; 270 } else if (secound < third) { 271 double result24 = first / (third - secound); 272 String[] DivAndSub2 = new String[] { String.format("%.0f", first), String.format("%.0f", third), 273 String.format("%.0f", secound), String.format("%.2f", result24), String.valueOf(24), "/", "-", 274 null, "(", null, ")" }; 275 return DivAndSub2; 276 } else { 277 twoOperatorAndOperator(num1, num2); 278 } 279 case 25: 280 double result25 = first * (secound * third); 281 String[] MulAndMul2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 282 String.format("%.0f", third), String.format("%.0f", result25), String.valueOf(25), "*", "*", null, 283 "(", null, ")" }; 284 return MulAndMul2; 285 286 case 26: 287 if (third != 0) { 288 double result26 = first * (secound / third); 289 String[] MulAndDiv2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 290 String.format("%.0f", third), String.format("%.2f", result26), String.valueOf(26), "*", "/", 291 null, "(", null, ")" }; 292 return MulAndDiv2; 293 } else { 294 twoOperatorAndOperator(num1, num2); 295 } 296 297 case 27: 298 if (secound*third != 0) { 299 double result27 = first / (secound * third); 300 String[] DivAndMul2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 301 String.format("%.0f", third), String.format("%.2f", result27), String.valueOf(27), "/", "*", 302 null, "(", null, ")" }; 303 return DivAndMul2; 304 } else { 305 twoOperatorAndOperator(num1, num2); 306 } 307 case 28: 308 if(secound / third!=0&& third!=0){ 309 double result28 = first / (secound / third); 310 String[] DivAndDiv2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound), 311 String.format("%.0f", third), String.format("%.2f", result28), String.valueOf(28), "/", "/", 312 null, "(", null, ")" }; 313 return DivAndDiv2; 314 }else { 315 twoOperatorAndOperator(num1, num2); 316 } 317 default: 318 break; 319 } 320 return null; 321 322 }
1.2 生成指定数目和范围的题目
1 /** 2 * twoOperator2() 方法,处理参数,并形成新的list集合的对象放入到session中,网页遍历可直接获取 3 * 4 * @param exerciseNumber 5 * 生成题目数量 6 * @param num1 7 * 定义起始范围 num1 8 * @param num2 9 * 定义起始范围 num2 10 * @return 返回list集合exerciseTwoOperators 11 */ 12 13 public static List<TwoOperators> twoOperator2(int exerciseNumber, int num1, int num2) { 14 15 List<TwoOperators> exerciseTwoOperators = new ArrayList<TwoOperators>(); 16 TwoOperators twoOperator = null; 17 for (int i = 0; i < exerciseNumber; i++) { 18 String[] twoOperatorAndOperator = twoOperatorAndOperator(num1, num2); 19 try { 20 twoOperator = new TwoOperators(twoOperatorAndOperator[0], twoOperatorAndOperator[1], 21 twoOperatorAndOperator[2], twoOperatorAndOperator[3], twoOperatorAndOperator[5], 22 twoOperatorAndOperator[6], twoOperatorAndOperator[7], twoOperatorAndOperator[8], 23 twoOperatorAndOperator[9], twoOperatorAndOperator[10]); 24 exerciseTwoOperators.add(twoOperator); 25 } catch (Exception e) { 26 e.printStackTrace(); 27 } 28 } 29 return exerciseTwoOperators; 30 31 }
1.3 action类中的代码
1 public class ThirdGrade { 2 private int min; 3 private int max; 4 private int exerciseNumber; 5 public int getMin() { 6 return min; 7 } 8 public void setMin(int min) { 9 this.min = min; 10 } 11 public int getMax() { 12 return max; 13 } 14 public void setMax(int max) { 15 this.max = max; 16 } 17 public int getExerciseNumber() { 18 return exerciseNumber; 19 } 20 public void setExerciseNumber(int exerciseNumber) { 21 this.exerciseNumber = exerciseNumber; 22 } 23 24 public String execute(){ 25 26 ActionContext actioncontext = ActionContext.getContext(); 27 Map<String, Object> session = actioncontext.getSession(); 28 count2 cou2=new count2(); 29 @SuppressWarnings("static-access") 30 List<TwoOperators> twoOperators=cou2.twoOperator2(exerciseNumber, min, max); 31 System.out.println("twoOperators = "+twoOperators); 32 session.put("twoOperators", twoOperators); 33 return "thirdGradeSuccess"; 34 } 35 36 }
2 .运行结果截图
2.1 初始界面
2.2 用户填写
2.3 回答问题页面
2.4 回答问题
2.5 判断回答结果(判断结果代码在之后)
转载于:https://www.cnblogs.com/orchid9/p/6685485.html
自动生成数学题型二(框架struts2)题型如((a+b)*c=d)相关推荐
- XPosed插件自动生成支付宝收款二维码
一.前言 前一段时间才偶然看到这个论坛,并且看了一篇@jiangwei212 大神的<Android支付宝蚂蚁森林能量自动收取插件开发原理解析>,这才知道XPosed和VirtualXPo ...
- c 自动生成html报告,Pytest框架之 - Allure生成漂亮的HTML图形测试报告
官网介绍 1. Allure Framework是一种灵活的轻量级多语言测试报告工具,不仅可以以简洁的Web报告形式非常简洁地显示已测试的内容,也允许参与开发过程的每个人从日常测试中提取最大程度的有用 ...
- 如何让pbootcms模板自动生成当前页面二维码-教程
二维码生成标签 {pboot:qrcode string=***} 使用说明: 用于生成对应文本的二维码图片,可用于产品列表页或详情页为每个产品生成二维码 :{pboot:qrcode string= ...
- 通过web系统实现淘宝营销引流,小说或者视频上传之后自动生成二维码,通过二维码分享之后引入微信或者扣扣加群,群满自动切换到下一个,以及数据统计分析和若干个小工具集成
通过web系统实现淘宝营销引流,小说或者视频上传之后自动生成二维码,通过二维码分享之后引入微信或者扣扣加群,群满自动切换到下一个,以及数据统计分析和若干个小工具集成. 主要实现技术: 1.大文件视频分 ...
- 接口自动化测试框架开发 | Pytest+Allure+AIOHTTP+用例自动生成
测试开发实战技能进阶学习,文末加群! 近期准备优先做接口测试的覆盖,为此需要开发一个测试框架,经过思考,这次依然想做点儿不一样的东西. 接口测试是比较讲究效率的,测试人员会希望很快能得到结果反馈,然而 ...
- Spring Boot(九)Swagger2自动生成接口文档和Mock模拟数据
一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 问题二 ...
- idea swagger生成接口文档_Spring Boot(九)Swagger2自动生成接口文档和Mock模拟数据...
一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 问题二 ...
- 如何自动生成『状态机』代码?
关注.星标公众号,直达精彩内容 来源:网络素材 有限自动机(Finite Automata Machine)是计算机科学的重要基石,它在软件开发领域内通常被称作有限状态机(Finite State M ...
- WAIC 2021 | 好未来副总裁吴中勤:多模态机器学习与自动生成技术
机器之心报道 机器之心编辑部 在 WAIC 2021 AI 开发者论坛上,好未来集团技术副总裁吴中勤发表主题演讲<多模态机器学习及大规模自动生成技术:算法框架.行业实践>,他主要介绍了多模 ...
最新文章
- 微软称不放弃收购雅虎
- 【论文知识点笔记】GNN概述(图神经网络概述)
- 英伟达RTX 3080值不值得抢?在TensorFlow上训练了卷积网络
- FPGA同步复位设计代码
- Rails 4.1.0 安装笔记
- Oracle创建新用户一系列操作模板
- MATLAB显示图像变白问题
- pop3接收网易163邮件及下载超大附件
- Laraval-admin 自定义form组件
- 极简图床中文教程-七牛云CDN永久免费图片外链
- 7天从代码入门到开发应用,怎样快速提高代码能力?
- python阿拉伯数字转换为英文_python实现将英文单词表示的数字转换成阿拉伯数字的方法...
- 个人日记-《学习究竟是什么》读后感-2020/6/21
- Centos7.4.1708 安装usb无限网卡驱动
- 意识理论综述:众多竞争的意识理论如何相互关联?
- 损失函数与正则项(惩罚项),多loss间权重设计
- 访问ip不在白名单中,请参考FAQ:
- 关于Criteria
- ApacheCN×Tesra 免费算力申请活动
- 小红书数据监测,品牌方必看的笔记投放技巧!
热门文章
- Android Studio 2.2:新布局、Firebase、OpenJDK以及Java 8
- 理解和使用SQL Server中的并行
- python自动加载配置文件中模块名_python----读取配置文件(configparser模块)
- dll侧加载_动态载入DLL所需要的三个函数详解(LoadLibrary,GetProcAddress,FreeLibrary)...
- dreamcast游戏_《Dreamcast Collection》开箱及游戏介绍
- mfc做数独游戏_我终于在iPhone上找到了体验最好的数独游戏
- 矩阵的Cholesky分解
- 二甲医院云服务器,医院用上云计算 病情上传到云端可行否?
- PostgreSQL 12系统表(10)pg_locks
- java中一级缓存_java – 集群环境中的hibernate一级缓存