自动生成数学题型二(框架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.访问数据 ...
随机推荐
- ES6-01:常量与变量的声明
首先,我们声明一个变量: //定义一个变量num,并赋值为10: let num = 10; //进行打印 console.log(num); let与var有所不同: 语法特点1:let变量只能在当 ...
- 阿里云开发之OSS数据迁移
最近由于项目需求,需要将一个aliyun账号下的oss数据导入到两一个aliyun账号下的oss,经过一番坎坷,最终搞定. 1.查看oss数据迁移官方文档,我是在本地windows电脑上进行操作的,先 ...
- 在Vue中通过自定义指令获取元素
vue.js 是数据绑定的框架,大部分情况下我们都不需要直接操作 DOM Element,但在某些时候,我们还是有获取DOM Element的需求的: 在 vue.js 中,获取某个DOM Eleme ...
- ORM 实现数据库表的增删改查
这次通过反射技术来实现一下数据库表的增删改查对象关系映射(英语:Object Relational Mapping,简称ORM,或O/RM,或O/R mapping) 注:引用时约束了以下几点: 数据 ...
- 移动H5开发入门知识,CSS的单位汇总与用法
说到css的单位,大家应该首先想到的是px,也就是像素,我们在网页布局中一般都是用px,但是近年来自适应网页布局越来越多,em和百分比也经常用到了.然后随着手机的流行,web app和hybrid a ...
- 搭建windows环境下(nginx+mysql+php)开发环境
搭建windows环境下(nginx+mysql+php)开发环境 1. 所需准备应用程序包 1.1 nginx 程序包nginx-1.0.4.zip或其他版本(下载地址: http ...
- IE浏览器下使用AJAX登陆接口请求缓存与登陆不了的问题解决
问题: 在IE浏览器下面,登陆的时候老是登陆不上,但是打开控制台的时候再登陆却能登陆上. 分析: 通过抓包,发现,在不打开控制台的时候,少了一个接口的请求,却返回了改接口的返回信息,但是返回信息并不是 ...
- Apache Flume日志收集系统简介
Apache Flume是一个分布式.可靠.可用的系统,用于从大量不同的源有效地收集.聚合.移动大量日志数据进行集中式数据存储. Flume简介 Flume的核心是Agent,Agent中包含Sour ...
- RabbitMQ-从基础到实战(2)— 防止消息丢失
转载请注明出处 1.简介 RabbitMQ中,消息丢失可以简单的分为两种:客户端丢失和服务端丢失.针对这两种消息丢失,RabbitMQ都给出了相应的解决方案. 2.防止客户端丢失消息 如图,生产者P向 ...
- 用一个jsp实现对数据库发访问
<%@ page language="java" import="java.util.*" pageEncoding="gb2312" ...