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)的更多相关文章

  1. 自动生成数学题型一 (框架Struts2) 题型如(a+b=c)

    1. 加减乘除 1.1 随机生成制定范围的整数 /** * 随机产生一个被限定范围的整数 * * @param num1 * 定义起始范围 num1 * @param num2 * 定义终止范围 nu ...

  2. 自动生成DTO(Sugar框架)

    step1:启动api项目 step2:使用postman工具,填上接口地址http://localhost:7788/api/automapper/AutoMapperSuper step3:表格数 ...

  3. 自动生成数学题型三 (框架Struts2)题型如 a+b=c(a、b、c都为分数)

    1. 约分分数 1.1 保留质数 /** * 将数值放入到fraction数组中 * @param fen 简要放的 int类型数值 */ public void fenshu(int fen) { ...

  4. 利用免费二维码API自动生成网址图片二维码

    调用第三方接口生成二维码 官方地址:http://goqr.me/api/ 示例 https://api.qrserver.com/v1/create-qr-code/?size=180x180&am ...

  5. 自动生成DTO(EF框架)

    [0]安装相关工具包 PostgreSQL版本: Npgsql.EntityFrameworkCore.PostgreSQL Npgsql.EntityFrameworkCore.PostgreSQL ...

  6. 文件参数化-utp框架之根据yaml文件自动生成python文件+utp运行用例

    根据yaml文件自动生成python文件 utp框架: bin目录:存放执行文件(run.py) cases目录:存放生成的用例的python文件(该目录下的文件为根据data目录下的测试用例生成的p ...

  7. Spring Boot(九)Swagger2自动生成接口文档和Mock模拟数据

    一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 问题二 ...

  8. Spring Boot Swagger2自动生成接口文档

    一.简介 在当下这个前后端分离的技术趋势下,前端工程师过度依赖后端工程师的接口和数据,给开发带来了两大问题: 1.问题一.后端接口查看难:要怎么调用?参数怎么传递?有几个参数?参数都代表什么含义? 2 ...

  9. 《音乐商店》第4集:自动生成StoreManager控制器

    一.自动生成StoreManager控制器 二.查看 StoreManager 控制器的代码 现在,Store Manager 控制器中已经包含了一定数量的代码,我们从头到尾重新过一下. 1.访问数据 ...

随机推荐

  1. centOS7 mini配置linux服务器(三) 配置防火墙以及IPtables切换

    一.firewall介绍 CentOS 7中防火墙是一个非常的强大的功能,在CentOS 6.5中在iptables防火墙中进行了升级了. 1.官方介绍 The dynamic firewall da ...

  2. Java IO之File和IO

    本系列我们主要总结一下Java中的IO.NIO以及NIO2. java.io.File 学习Java IO,首先让我们来了解File类吧,它是文件和目录路径名的抽象表示形式.因此你千万别误会File类 ...

  3. Modbus软件开发实战指南 之 开发自己的Modbus Poll工具 - 1

    在开发Modbus程序的过程中,也可以发现经常需要使用诸如Modbus Poll和Modbus Slave等辅助调试工具, 用于验证MODBUS通讯消息是否正确.但是,Modbus Poll和Modb ...

  4. wemall app商城源码Fragment中监听onKey事件

    wemall-mobile是基于WeMall的android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享android开发Fragment中监听onK ...

  5. Visual Studio 2017正式版安装

    Visual Studio号称宇宙第一IDE, 2017年3月7日强大的微软帝国时隔两年多终于发布新一代IDE Visual Studio 2017.支持的功能简直不能太多,详情移步:https:// ...

  6. git 由http切换成git

    项目中经常会遇到http 的git 协议为了安全切换成ssh 的git 协议. 这个时候,只要使用如下命令变更 remote 字符串就好了. git remote set-url origin git ...

  7. 【方法】Oracle用户密码含特殊字符时的登陆问题

    [方法]Oracle用户密码含特殊字符时的登陆问题 1.1  BLOG文档结构图 1.2  前言部分 1.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它 ...

  8. Dubbo java.io.IOException: Can not lock the registry cache file

    跑单测用例的时候,以前执行成功的用例,运行时控制台仍然会报 dubbo 相关的错误: Failed to save registry store file, cause: Can not lock t ...

  9. MyEclipse10的正确破解方法

    无法转载,故给出原文链接,以供需要者. MyEclipse10的正确破解方法

  10. (25)IO流之转换流InputStreamReader和OutputStreamWriter

    InputStreamReader:字节到字符的桥梁. OutputStreamWriter:字符到字节的桥梁. 它们有转换作用,而本身又是字符流.所以在构造的时候,需要传入字节流对象进来. 构造函数 ...