防摸鱼太久智商降低,口算练习册

智商检测

为了防止摸鱼太久智商变低,所以开发了口算练习册。

有难度选择,得分

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;
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值