智商检测
为了防止摸鱼太久智商变低,所以开发了口算练习册。
有难度选择,得分
import java.util.Random;
import java.util.Scanner;
/**
* 为了防止摸鱼太久智商变低,开发了口算练习册,不服来战!
*
* @author Xiongxm
* @since 2022/12/21 creation
*/
public class OralArithmeticWorkbook {
private static int difficult = 1;
private static boolean flg = true;
private static int score = 0;
public static void main(String[] args) {
oralArithmeticWorkbook();
}
public static void oralArithmeticWorkbook() {
Scanner scanner = new Scanner(System.in);
while (flg) {
System.out.println("口算练习册,不服来战,输入fw可停止作答,输入way1/2/3选择难度,例way3");
Random random = new Random();
switch (difficult) {
case 1:
int a = random.nextInt(100);
int b = random.nextInt(10);
System.out.println(a + "+" + b + "= ?");
System.out.print("输入答案:");
String answerLine1 = scanner.nextLine();
isRight(a + b, answerLine1, 5);
break;
case 2:
int c = random.nextInt(1000);
int d = random.nextInt(1000);
int jiaOrJian = random.nextInt(100);
if (jiaOrJian > 50) {
jiaOrJian = -1;
} else jiaOrJian = 1;
if (jiaOrJian == 1) {
System.out.println(c + "+" + d + "= ?");
} else if (jiaOrJian == -1) {
System.out.println(c + "-" + d + "= ?");
}
System.out.print("输入答案:");
String answerLine2 = scanner.nextLine();
isRight(c + jiaOrJian * d, answerLine2, 10);
break;
case 3:
int e = random.nextInt(100);
int f = random.nextInt(10);
System.out.println(e + " * " + f + " = ?");
System.out.print("输入答案:");
String answerLine3 = scanner.nextLine();
isRight(e * f, answerLine3, 20);
break;
default:
System.out.println("没了。。。");
break;
}
}
}
public static void isRight(int rightAnswer, String answerLine, int scoreEveryTitle) {
if ("fw".equals(answerLine)) {
System.out.println("我是得了" + score + "分的小fw~~");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
flg = false;
return;
}
try {
int answer = Integer.valueOf(answerLine);
if (answer != rightAnswer) {
score -= 10;
System.out.println("错了fw,正确答案:" + rightAnswer + "。扣10分,当前得分:" + score + "分.");
} else {
score += scoreEveryTitle;
System.out.println("算对了嘛,当前得分 " + score + " 分.");
}
System.out.println("-------------------------------------------------------------");
} catch (NumberFormatException e) {
switch (answerLine) {
case "way1":
difficult = 1;
break;
case "way2":
difficult = 2;
break;
case "way3":
difficult = 3;
break;
default:
score -= 10000;
System.out.println("别乱输,fw,扣10000分,当前得分: " + score + " 分.");
System.out.println("-------------------------------------------------------------");
break;
}
}
}
}