package pack1;

public class Suanshi {
private int can1;
private int can2;
private int result;
private char op;

public int getCan1() {        
    return can1;             
}                            
                             
public void setCan1(int can1)
    this.can1 = can1;        
}                            
                             
public int getCan2() {        
    return can2;             
}                            
                             
public void setCan2(int can2)
    this.can2 = can2;        
}                            
                             
public int getResult() {      
    return result;           
}                            
                             
public void setResult(int res
    this.result = result;    
}                            
                             
public char getOp() {         
    return op;               
}                            
                             
public void setOp(char op) { 
    this.op = op;            
}                            
                             
public Suanshi(int can1, int 
    this.can1 = can1;        
    this.can2 = can2;        
    this.result = result;    
    this.op = op;            
                             
                             
}                            
public int result1(){         
    if(op=='+')              
        return can1+can2;    
    else if(op=='-')         
        return can1-can2;    
    else if(op=='*')         
        return can1*can2;    
    else if(op=='/')         
        return can1/can2;    
    else                     
        return 0;            
}                            

}
//--------------------------
package pack1;

import java.math.BigInteger;
import java.util.Random;
import java.util.Scanner;

public class Test1 {
static Suanshi[] suanshi = new Suanshi[10086];
static int[] result = new int[10086];
static int arr1[] = new int[10086];
static int dui=0,cuo=0;
public static void menu() {
System.out.println("1.生成题目");
System.out.println("2.输出答案");
System.out.println("3.判断对错");
System.out.println("4.退出");
}

static Scanner sc = new Scanner(System.in);

public static void main(String[] args) {
    int n = 0;
    while (true) {
        menu();
        n = sc.nextInt();
        switch (n) {
            case 1:
                generate();
                break;
            case 2:
                print();
                break;
            case 3:
                judge();
                break;
            case 4:
                System.exit(0);
                break;
            default:
                System.out.println("输入错误");
                break;
        }


    }


}

private static void judge() {
    System.out.println("正确"+dui+"个");
    System.out.println("错误"+cuo+"个");

}

private static void print() {
    for(int i=1;i<=30;i++){
        System.out.println(suanshi[i].getCan1()+" "+suanshi[i].getOp()+" "+suanshi[i].getCan2()+"="+suanshi[i].getResult());
    }

}

private static void generate() {
    Random rand1 = new Random();
    Random rand2 = new Random();
    Random rand3 = new Random();
    int a = rand3.nextInt(4) + 1;
    for (int i = 1; i <= 30; i++) {
        int x = rand1.nextInt(10) + 1;
        int y = rand2.nextInt(10) + 1;
        if (a == 1) {
            suanshi[i] = new Suanshi(x, y, x + y, '+');
        } else if (a == 2) {
            suanshi[i] = new Suanshi(x, y, x - y, '-');
        } else if (a == 3) {
            suanshi[i] = new Suanshi(x, y, x * y, '*');
        } else if (a == 4) {
            suanshi[i] = new Suanshi(x, y, x / y, '/');
        }


    }
    for(int i=1;i<=30;i++){
        System.out.println(suanshi[i].getCan1()+" "+suanshi[i].getOp()+" "+suanshi[i].getCan2()+"=");
        result[i]=sc.nextInt();
        if(result[i]==suanshi[i].result1())
        {System.out.println("正确");dui++;}
        else
        {System.out.println("错误");cuo++;}


    }


}

}

posted on 2025-09-27 20:16  douzishuo  阅读(9)  评论(0)    收藏  举报