自动生成数学题型二(框架struts2)题型如((a+b)*c=d)

时间:2022-12-05 21:02:27

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 初始界面

自动生成数学题型二(框架struts2)题型如((a+b)*c=d)

2.2 用户填写

自动生成数学题型二(框架struts2)题型如((a+b)*c=d)

2.3 回答问题页面

自动生成数学题型二(框架struts2)题型如((a+b)*c=d)

2.4 回答问题

自动生成数学题型二(框架struts2)题型如((a+b)*c=d)

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

自动生成数学题型二(框架struts2)题型如((a+b)*c=d)