自动生成数学题型二(框架struts2)题型如((a+b)*c=d)
1. 生成题目
1.1 生成单个题目
public static String[] twoOperatorAndOperator(int num1, int num2) {
double first = generate(num1, num2);
double secound = generate(num1, num2);
double third = generate(num1, num2);
System.out.println(num1+" num1");
System.out.println(num2+" num2");
int zero = 0;
zero=generate(1, 28);
System.out.println(zero + " zero");
switch (zero) {
case 1:
double result = first + secound + third;
String[] addAndAdd = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result), String.valueOf(1), "+", "+", null,
null, null, null };
return addAndAdd;
case 2:
if (first + secound >= third) {
double result2 = first + secound - third;
String[] addAndSub = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result2), String.valueOf(2), "+", "-", null,
null, null, null };
return addAndSub;
} else {
double result2 = third + secound - first;
String[] addAndSub = new String[] { String.format("%.0f", third), String.format("%.0f", secound),
String.format("%.0f", first), String.format("%.0f", result2), String.valueOf(2), "+", "-", null,
null, null, null };
return addAndSub;
}
case 3:
double result3 = first + secound * third;
String[] addAndMul = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result3), String.valueOf(3), "+", "*", null,
null, null, null };
return addAndMul;
case 4:
if (third != 0) {
double result4 = first + secound / third;
String[] addAndDiv = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result4), String.valueOf(4), "+", "/", null,
null, null, null };
return addAndDiv;
} else {
twoOperatorAndOperator(num1, num2);
}
case 5:
if (first - secound + third >= 0) {
double result5 = first - secound + third;
String[] SubAndAdd = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result5), String.valueOf(5), "-", "+", null,
null, null, null };
return SubAndAdd;
} else {
double result5 = secound - first - third;
String[] SubAndAdd = new String[] { String.format("%.0f", secound), String.format("%.0f", first),
String.format("%.0f", third), String.format("%.0f", result5), String.valueOf(5), "-", "-", null,
null, null, null };
return SubAndAdd;
}
case 6:
if (first - secound - third >= 0) {
double result6 = first - secound - third;
String[] SubAndSub = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result6), String.valueOf(6), "-", "-", null,
null, null, null };
return SubAndSub;
} else {
double result6 = third + secound - first;
String[] SubAndSub = new String[] { String.format("%.0f", third), String.format("%.0f", secound),
String.format("%.0f", first), String.format("%.0f", result6), String.valueOf(6), "+", "-", null,
null, null, null };
return SubAndSub;
}
case 7:
if (first - secound * third > 0) {
double result7 = first - secound * third;
String[] SubAndMul = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result7), String.valueOf(7), "-", "*", null,
null, null, null };
return SubAndMul;
} else {
double result7 = third * secound - first;
String[] SubAndMul = new String[] { String.format("%.0f", third), String.format("%.0f", secound),
String.format("%.0f", first), String.format("%.0f", result7), String.valueOf(7), "*", "-", null,
null, null, null };
return SubAndMul;
}
case 8:
if (third != 0) {
if (first - secound / third > 0) {
double result8 = first - secound / third;
String[] SubAndDiv = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result8), String.valueOf(8), "-", "/",
null, null, null, null };
return SubAndDiv;
} else {
double result8 = secound / third - first;
String[] SubAndDiv = new String[] { String.format("%.0f", secound), String.format("%.0f", third),
String.format("%.0f", first), String.format("%.2f", result8), String.valueOf(8), "/", "-",
null, null, null, null };
return SubAndDiv;
}
} else {
twoOperatorAndOperator(num1, num2);
}
case 9:
double result9 = first * secound + third;
String[] MulAndAdd = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result9), String.valueOf(9), "*", "+", null,
null, null, null };
return MulAndAdd;
case 10:
if (first * secound - third > 0) {
double result10 = first * secound - third;
String[] MulAndSub = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result10), String.valueOf(10), "*", "-",
null, null, null, null };
return MulAndSub;
} else {
double result10 = third - first * secound;
String[] MulAndSub = new String[] { String.format("%.0f", third), String.format("%.0f", first),
String.format("%.0f", secound), String.format("%.0f", result10), String.valueOf(10), "-", "*",
null, null, null, null };
return MulAndSub;
}
case 11:
double result11 = first * secound * third;
String[] MulAndMul = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result11), String.valueOf(11), "*", "*", null,
null, null, null };
return MulAndMul;
case 12:
if (third != 0) {
double result12 = first * secound / third;
String[] MulAndDiv = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result12), String.valueOf(12), "*", "/",
null, null, null, null };
return MulAndDiv;
} else {
twoOperatorAndOperator(num1, num2);
}
case 13:
if (secound != 0) {
double result13 = first / secound + third;
String[] DivAndAdd = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result13), String.valueOf(13), "/", "+",
null, null, null, null };
return DivAndAdd;
} else {
twoOperatorAndOperator(num1, num2);
}
case 14:
if (secound > 0) {
if (first / secound - third > 0) {
double result14 = first / secound - third;
String[] DivAndSub = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result14), String.valueOf(14), "/", "-",
null, null, null, null };
return DivAndSub;
} else {
double result14 = third - first / secound;
String[] DivAndSub = new String[] { String.format("%.0f", third), String.format("%.0f", first),
String.format("%.0f", secound), String.format("%.2f", result14), String.valueOf(14), "-",
"/", null, null, null, null };
return DivAndSub;
}
} else {
twoOperatorAndOperator(num1, num2);
}
case 15:
if (secound != 0) {
double result15 = first / secound * third;
String[] DivAndMul = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result15), String.valueOf(15), "/", "*",
null, null, null, null };
return DivAndMul;
} else {
twoOperatorAndOperator(num1, num2);
}
case 16:
if (secound != 0 && third != 0) {
double result16 = first / secound / third;
String[] DivAndDiv = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result16), String.valueOf(16), "/", "/",
null, null, null, null };
return DivAndDiv;
} else {
twoOperatorAndOperator(num1, num2);
}
case 17:
double result17 = (first + secound) * third;
String[] AddAndMul2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result17), String.valueOf(17), "+", "*", "(",
null, ")", null };
return AddAndMul2;
case 18:
if (third != 0) {
double result18 = (first + secound) / third;
String[] AddAndDiv2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result18), String.valueOf(18), "+", "/",
"(", null, ")", null };
return AddAndDiv2;
} else {
twoOperatorAndOperator(num1, num2);
}
case 19:
if (first > secound) {
double result19 = (first - secound) * third;
String[] SubAndMul2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result19), String.valueOf(19), "-", "*",
"(", null, ")", null };
return SubAndMul2;
} else {
double result19 = (secound - first) * third;
String[] SubAndMul2 = new String[] { String.format("%.0f", secound), String.format("%.0f", first),
String.format("%.0f", third), String.format("%.0f", result19), String.valueOf(19), "-", "*",
"(", null, ")", null };
return SubAndMul2;
}
case 20:
if (third != 0) {
double result20 = (first + secound) / third;
String[] SubAndDiv2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result20), String.valueOf(20), "+", "/",
"(", null, ")", null };
return SubAndDiv2;
} else {
twoOperatorAndOperator(num1, num2);
}
case 21:
double result21 = first * (secound + third);
String[] MulAndAdd2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result21), String.valueOf(21), "*", "+", null,
"(", null, ")" };
return MulAndAdd2;
case 22:
if (secound > third) {
double result22 = first * (secound - third);
String[] MulAndSub2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result22), String.valueOf(22), "*", "-",
null, "(", null, ")" };
return MulAndSub2;
} else {
double result22 = first * (third - secound);
String[] MulAndSub2 = new String[] { String.format("%.0f", first), String.format("%.0f", third),
String.format("%.0f", secound), String.format("%.2f", result22), String.valueOf(22), "*", "-",
null, "(", null, ")" };
return MulAndSub2;
}
case 23:
if ((secound + third) != 0) {
double result23 = first / (secound + third);
String[] DivAndAdd2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result23), String.valueOf(23), "/", "+",
null, "(", null, ")" };
return DivAndAdd2;
} else {
twoOperatorAndOperator(num1, num2);
}
case 24:
if (secound > third) {
double result24 = first / (secound - third);
String[] DivAndSub2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result24), String.valueOf(24), "/", "-",
null, "(", null, ")" };
return DivAndSub2;
} else if (secound < third) {
double result24 = first / (third - secound);
String[] DivAndSub2 = new String[] { String.format("%.0f", first), String.format("%.0f", third),
String.format("%.0f", secound), String.format("%.2f", result24), String.valueOf(24), "/", "-",
null, "(", null, ")" };
return DivAndSub2;
} else {
twoOperatorAndOperator(num1, num2);
}
case 25:
double result25 = first * (secound * third);
String[] MulAndMul2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.0f", result25), String.valueOf(25), "*", "*", null,
"(", null, ")" };
return MulAndMul2;
case 26:
if (third != 0) {
double result26 = first * (secound / third);
String[] MulAndDiv2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result26), String.valueOf(26), "*", "/",
null, "(", null, ")" };
return MulAndDiv2;
} else {
twoOperatorAndOperator(num1, num2);
}
case 27:
if (secound*third != 0) {
double result27 = first / (secound * third);
String[] DivAndMul2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result27), String.valueOf(27), "/", "*",
null, "(", null, ")" };
return DivAndMul2;
} else {
twoOperatorAndOperator(num1, num2);
}
case 28:
if(secound / third!=0&& third!=0){
double result28 = first / (secound / third);
String[] DivAndDiv2 = new String[] { String.format("%.0f", first), String.format("%.0f", secound),
String.format("%.0f", third), String.format("%.2f", result28), String.valueOf(28), "/", "/",
null, "(", null, ")" };
return DivAndDiv2;
}else {
twoOperatorAndOperator(num1, num2);
}
default:
break;
}
return null;
}
1.2 生成指定数目和范围的题目
/**
* twoOperator2() 方法,处理参数,并形成新的list集合的对象放入到session中,网页遍历可直接获取
*
* @param exerciseNumber
* 生成题目数量
* @param num1
* 定义起始范围 num1
* @param num2
* 定义起始范围 num2
* @return 返回list集合exerciseTwoOperators
*/ public static List<TwoOperators> twoOperator2(int exerciseNumber, int num1, int num2) { List<TwoOperators> exerciseTwoOperators = new ArrayList<TwoOperators>();
TwoOperators twoOperator = null;
for (int i = 0; i < exerciseNumber; i++) {
String[] twoOperatorAndOperator = twoOperatorAndOperator(num1, num2);
try {
twoOperator = new TwoOperators(twoOperatorAndOperator[0], twoOperatorAndOperator[1],
twoOperatorAndOperator[2], twoOperatorAndOperator[3], twoOperatorAndOperator[5],
twoOperatorAndOperator[6], twoOperatorAndOperator[7], twoOperatorAndOperator[8],
twoOperatorAndOperator[9], twoOperatorAndOperator[10]);
exerciseTwoOperators.add(twoOperator);
} catch (Exception e) {
e.printStackTrace();
}
}
return exerciseTwoOperators; }
1.3 action类中的代码
public class ThirdGrade {
private int min;
private int max;
private int exerciseNumber;
public int getMin() {
return min;
}
public void setMin(int min) {
this.min = min;
}
public int getMax() {
return max;
}
public void setMax(int max) {
this.max = max;
}
public int getExerciseNumber() {
return exerciseNumber;
}
public void setExerciseNumber(int exerciseNumber) {
this.exerciseNumber = exerciseNumber;
}
public String execute(){
ActionContext actioncontext = ActionContext.getContext();
Map<String, Object> session = actioncontext.getSession();
count2 cou2=new count2();
@SuppressWarnings("static-access")
List<TwoOperators> twoOperators=cou2.twoOperator2(exerciseNumber, min, max);
System.out.println("twoOperators = "+twoOperators);
session.put("twoOperators", twoOperators);
return "thirdGradeSuccess";
}
}
2 .运行结果截图
2.1 初始界面

2.2 用户填写

2.3 回答问题页面

2.4 回答问题

2.5 判断回答结果(判断结果代码在之后)

自动生成数学题型二(框架struts2)题型如((a+b)*c=d)的更多相关文章
- 自动生成数学题型一 (框架Struts2) 题型如(a+b=c)
1. 加减乘除 1.1 随机生成制定范围的整数 /** * 随机产生一个被限定范围的整数 * * @param num1 * 定义起始范围 num1 * @param num2 * 定义终止范围 nu ...
- 自动生成DTO(Sugar框架)
step1:启动api项目 step2:使用postman工具,填上接口地址http://localhost:7788/api/automapper/AutoMapperSuper step3:表格数 ...
- 自动生成数学题型三 (框架Struts2)题型如 a+b=c(a、b、c都为分数)
1. 约分分数 1.1 保留质数 /** * 将数值放入到fraction数组中 * @param fen 简要放的 int类型数值 */ public void fenshu(int fen) { ...
- 利用免费二维码API自动生成网址图片二维码
调用第三方接口生成二维码 官方地址:http://goqr.me/api/ 示例 https://api.qrserver.com/v1/create-qr-code/?size=180x180&am ...
- 自动生成DTO(EF框架)
[0]安装相关工具包 PostgreSQL版本: Npgsql.EntityFrameworkCore.PostgreSQL Npgsql.EntityFrameworkCore.PostgreSQL ...
- 文件参数化-utp框架之根据yaml文件自动生成python文件+utp运行用例
根据yaml文件自动生成python文件 utp框架: bin目录:存放执行文件(run.py) cases目录:存放生成的用例的python文件(该目录下的文件为根据data目录下的测试用例生成的p ...
- Spring Boot(九)Swagger2自动生成接口文档和Mock模拟数据
一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 问题二 ...
- Spring Boot Swagger2自动生成接口文档
一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 1.问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 2 ...
- 《音乐商店》第4集:自动生成StoreManager控制器
一.自动生成StoreManager控制器 二.查看 StoreManager 控制器的代码 现在,Store Manager 控制器中已经包含了一定数量的代码,我们从头到尾重新过一下. 1.访问数据 ...
随机推荐
- .net平台的rabbitmq使用封装
前言 RabbitMq大家再熟悉不过,这篇文章主要整对rabbitmq学习后封装RabbitMQ.Client的一个分享.文章最后,我会把封装组件和demo奉上. Rabbitmq的运作 从下图可以看 ...
- iOS性能检测之Instrunments - 几种常用工具简单介绍
Instrunments: 没错,就是这货,很多人平时开发可能不一定会用到这个,但我要说的是,学会使用它,会让你加分不少哦 先来一张全家福: 1.打开方式 或者 两种方式都行. 2.今天主要介绍一下 ...
- 学好UI你必须要掌握这些技术
转自:http://blog.sina.com.cn/s/blog_15da22ed10102x0gx.html ui设计现在已经是设计行业中的瞩目之星,无论在PC端.移动端还是游戏上都是大放异彩. ...
- 解决https证书验证不通过的问题
1.报错信息 java.security.cert.CertificateException: No name matching api.weibo.com found; nested excepti ...
- linux的文件权限小结
对于初接触Linux的朋友来说,会有各种不习惯和各种昏头,文件的权限就很让人不知所措. ls命令以及字段含义 比如我们列出当前目录文件: 我们来看下上述大致含义: 第1行显示的信息: 总用量(tota ...
- 【Rsync项目实战】备份全网服务器数据
[Rsync项目实战]备份全网服务器数据 标签(空格分隔): Linux服务搭建-陈思齐 ---本教学笔记是本人学习和工作生涯中的摘记整理而成,此为初稿(尚有诸多不完善之处),为原创作品,允许转载,转 ...
- 走进 Redis 的世界
NoSQL(Not Only SQL) 在现今已经应用非常普遍了,尤其是 Redis 和 MongoDB.我们现在来说说 Redis. 前世 Redis 是一个意大利人 Salvatore Sanfi ...
- 浅谈EL
一.了解EL 1.EL是从 JavaScript 脚本语言得到启发的一种表达式语言,它借鉴了 JavaScript 多类型转换无关性的特点.在使用 EL 从 scope 中得到参数时可以自动转换类型, ...
- 【转】深入理解RunLoop
RunLoop 是 iOS 和 OS X 开发中非常基础的一个概念,这篇文章将从 CFRunLoop 的源码入手,介绍 RunLoop 的概念以及底层实现原理.之后会介绍一下在 iOS 中,苹果是如何 ...
- 用C写一个web服务器(二) I/O多路复用之epoll
.container { margin-right: auto; margin-left: auto; padding-left: 15px; padding-right: 15px } .conta ...