- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
public class MathGame {
public static Map<Integer, String> data = new HashMap<Integer, String>();
public static Map<String, Integer> result = new HashMap<String, Integer>();
String problem;
Random random = new Random();
public void NewProblem() {
String sign = null;
for (int i = 1; i < 5; i++) {
switch (GenNumber(3)) {
case 1:
sign = Sign.MINUS.get();
break;
case 2:
sign = Sign.PLUS.get();
break;
case 3:
sign = Sign.TIMES.get();
break;
default:
sign = Sign.PLUS.get();
break;
}
problem = GenNumber(9) + " " + sign + " " + GenNumber(9);
result.put(problem + " = ???", Decide(Integer.parseInt(
problem.split(" ")[0]), problem.split(" ")[1], Integer
.parseInt(problem.split(" ")[2])));
data.put(i, problem);
}
}
private int GenNumber(int s) {
return random.nextInt(s) + 1;
}
private int Decide(int a, String sign, int b) {
switch (sign) {
case "+":
return a + b;
case "-":
return a - b;
case "*":
return a * b;
}
return 0;
}
public enum Sign {
PLUS("+"),
MINUS("-"),
TIMES("*");
private final String sign;
Sign(String sign) {
this.sign = sign;
}
public String get() {
return sign;
}
}
}
Комментарии (0) RSS
Добавить комментарий