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. myeclipse2015 安装配置

    本人提供<myeclipse2015 安装过程及破解资源> 链接:http://pan.baidu.com/s/1o79wwMQ 密码:crnp 安装步骤 1.安装jdk: http:// ...

  2. C#调用PB写的com组件dll

    背景 小编为了使用C#去模仿PB代码的加密算法,结果发现PB算法中,的long类型只有21亿,实际上传入的数值达到了78亿,造成了数据溢出,精度丢失的情况. 然而PB的算法已经使用C#不可以还原(C# ...

  3. php写购物车(思路&源码)

    本文介绍一个php实现的购物车代码,功能实现完整,具有一定的参考价值 这里我们为你提供个简单的php购物车代码,从增加购物产品与发生购买了,在商城开发中,这个功能是少不了的 具体分析如下: 对购物车里 ...

  4. 获取bing图片并自动设置为电脑桌面背景(C++完整开源程序)

    众所周知,bing搜索网站首页每日会更新一张图片,张张漂亮(额,也有一些不合我口味的),特别适合用来做电脑壁纸. 我们想要将bing网站背景图片设置为电脑桌面背景的通常做法是: 上网,搜索bing 找 ...

  5. 算法模板——splay区间反转 1

    实现的功能:将序列区间反转,并维护 详见BZOJ3223 var i,j,k,l,m,n,head,a1,a2:longint; s1:ansistring; a,b,c,d,fat,lef,rig: ...

  6. UINavigationBar统一修改导航条样式

    #pragma mark -- 统一导航条样式 //统一导航条样式 UIFont *font = [UIFont systemFontOfSize:19.f]; NSDictionary *textA ...

  7. c#调用aapt查看apk文件信息功能实现

    第一篇随笔就此开始. 1. 起源 思路源自于项目开发过程中.需要确认apk文件版本以验证其功能差异以便于定位问题,于是度娘,得到APK信息查看器(APK-info)这个工具,其版本号为0.2.它能显示 ...

  8. 2017java预备作业2

    1 安装git • 到Git官网https://www.git-scm.com/ 下载Git客户端 • 安装时选择默认即可. • 安装完成后在桌面的快捷菜单中选择Git Bash Here 或者在开始 ...

  9. 完全关闭IIS日志,包括System32下的LogFile

    早上突然发现网站访问不了了,登陆服务器一看,是C盘满了. 查一看,是IIS产生了70多G的日志,但明明已关闭日志了,还是会产生. 产生的目录在:C:\Windows\System32\LogFiles ...

  10. PHPCMS二次开发——对栏目可用 limit 限定获取

    为了实现类似用limit调用栏目,故自定义了mylimit(这里不能用limit,因为系统在解析的时候会覆盖,所以自定义的limit就起不到作用) 参数,例如: {pc:content  action ...