四则运算第n版

主界面

 1 package pk1;
 2 import java.util.Random;
 3 import java.util.Scanner;
 4 public class sizeyunxuan {
 5     
 6 
 7     public static void main(String[] args) {
 8         
 9         Scanner scan =new Scanner(System.in);
10         int a,b,n,num,sum=0;
11         menu.menu();
12         
13         a=scan.nextInt();
14 
15         switch(a) {
16         case 1:System.out.println("请输入需要的题目数:");
17                ShuJu.N=scan.nextInt();
18                System.out.println("请输入需要的操作数(操作数需要大于等于2):");
19                ShuJu.n=scan.nextInt(); 
20                System.out.println("请输入数据位数限制(2/3/4)");
21                ShuJu.a=scan.nextInt(); 
22                System.out.println("  ");
23                menu.menu();
24                 a=scan.nextInt();
25                 
26 
27             switch(a) {
28               
29         case 2:Second.second();
30                System.out.println("是否查看错题集?(1是/2否)");
31               b=scan.nextInt();
32                if(b==1) {
33                     InTo.jixun();
34                 break;
35                       }
36                if(b==2) {
37              
38                break;
39                }
40 
41         case 3:Third.third();
42            System.out.println("是否查看错题集?(1是/2否)");
43             b=scan.nextInt();
44             if(b==1) {
45                  InTo.jixun();
46              break;
47                       }
48             if(b==2) {
49           
50             break;
51             }
52         case 4:Fourth.fourth();
53            System.out.println("是否查看错题集?(1是/2否)");
54             b=scan.nextInt();
55             if(b==1) {
56                  InTo.jixun();
57              break;
58                       }
59             if(b==2) {
60           
61             break;
62             }
63         case 5:InTo.jixun();
64         }
65         }
66     }

数据类

  1 package pk1;
  2 import java.util.Scanner;
  3 import java.util.Random;
  4 
  5 public class ShuJu {
  6     
  7    private int shuju1;//数据1
  8    private int shuju2;//数据2
  9 
 10    private String fuhao;//符号
 11    static int N;//题目个数
 12    static int n;//操作数个数
 13    static int a;//数据位数
 14   public static int shuju1() {
 15     
 16       int shuju1=0;
 17        Random r= new Random();
 18        if(a==2)
 19        { shuju1=r.nextInt(99);}
 20        else if(a==3)
 21        { shuju1=r.nextInt(999);}
 22        else if(a==4)
 23        { shuju1=r.nextInt(9999); }
 24        return shuju1;
 25 
 26       }
 27   public static int shuju2() {
 28         
 29       int shuju2=0;
 30        Random r= new Random();
 31        if(a==2)
 32        { shuju2=r.nextInt(99);}
 33        else if(a==3)
 34        { shuju2=r.nextInt(999);}
 35        else if(a==4)
 36        { shuju2=r.nextInt(9999); }
 37        return shuju2;
 38 
 39       }
 40       
 41     
 42   
 43  /* public static void shuju2(int a) {
 44       if (a==2) {
 45        Random r= new Random();
 46         int shuju2=r.nextInt(99);
 47         return shuju2;}
 48     }
 49   public static int shuju3() {
 50        Random r= new Random();
 51         int shuju1=r.nextInt(999);
 52         return shuju1;
 53     }
 54  
 55  public static int shuju4() {
 56        Random r= new Random();
 57         int shuju2=r.nextInt(999);
 58         return shuju2;
 59     }
 60  public static int shuju5() {
 61        Random r= new Random();
 62         int shuju1=r.nextInt(9999);
 63         return shuju1;
 64     }
 65 
 66 public static int shuju6() {
 67        Random r= new Random();
 68         int shuju2=r.nextInt(9999);
 69         return shuju2;
 70     }*/
 71   public static char yunsuan( ) {
 72         Random r=new Random();
 73         int t=(int)r.nextInt(4);
 74         char fuhao=' ';
 75         switch(t) {
 76         case 0:
 77             fuhao = '+';
 78             break;
 79         case 1:
 80                 fuhao = '-';
 81                 break;
 82         case 2:
 83                 fuhao = '*';
 84                 break;
 85          case 3:
 86                 fuhao = '/';
 87                 break;
 88         }
 89         return fuhao;
 90   }
 91   
 92   public int num() {
 93       
 94     return N;
 95       
 96   }
 97  
 98     ShuJu(int shuju1,int shuju2,String fuhao,int num,int n){
 99         this.shuju1=shuju1;
100         this.shuju2=shuju2;
101         this.fuhao=fuhao;
102         this.N=num;
103         this.n=n;
104     }
105     
106 
107    
108  }

菜单类

 1 package pk1;
 2 
 3 import java.util.Scanner;
 4 
 5 public class menu {
 6     public static void menu() {
 7     System.out.println("1.参数设置");
 8     System.out.println("2.小学二年级口算题");
 9     System.out.println("3.小学三年级口算题");
10     System.out.println("4.小学四年级口算题");
11     System.out.println("5.错题集");
12     System.out.println("请选择:");
13  
14 }
15 }

计算+判断+错题重做

  1 package pk1;
  2 
  3 import java.util.Scanner;
  4 
  5 public class InTo {
  6 
  7 
  8 private static ShuJu sj;
  9 static int nnum=0;
 10 static int ccount=0;
 11 static  int cuoticount=0;
 12 static String []arr = new String[100000];
 13 static int []zqda = new int[100000];
 14 static int []cishu = new int[100000];
 15 public static void chuti()
 16 {
 17     int a = sj.shuju1();
 18     int b = sj.shuju2();
 19     char c = sj.yunsuan();
 20     String str = ""+a+c+b;
 21     int []cunshu = new int[1000];
 22     char []cunfuhao =new char[1000];
 23     int shu=0;
 24     int fuhao=0;
 25     if(c=='*')
 26     {
 27         cunshu[shu]=a*b;
 28     }
 29     else if(c=='/')
 30     {
 31         cunshu[fuhao]=a/b;
 32     }
 33     else
 34     {
 35         cunshu[shu]=a;
 36         shu++;
 37         cunshu[shu]=b;
 38         cunfuhao[fuhao]=c;
 39     }
 40     
 41     for(int i=2;i<sj.n;i++)
 42     {
 43         int zenjiashu = sj.shuju1();
 44         char zenjiac = sj.yunsuan();
 45         if(zenjiac=='*')
 46         {
 47             cunshu[shu]=cunshu[shu]*zenjiashu;
 48         }
 49         else if(c=='/')
 50         {
 51             cunshu[shu]=cunshu[shu]/zenjiashu;
 52         }
 53         else
 54         {
 55             shu++;
 56             cunshu[shu]=zenjiashu;
 57             fuhao++;
 58             cunfuhao[fuhao]=zenjiac;
 59         }    
 60         str = str + zenjiac + zenjiashu;
 61     }
 62     int zhengquedaan=cunshu[0];
 63     int cou=0;
 64     for(int j=0;j<=fuhao;j++)
 65     {
 66         if(cunfuhao[cou]=='+')
 67         {
 68             zhengquedaan+=cunshu[cou+1];
 69         }
 70         else
 71         {
 72             zhengquedaan-=cunshu[cou+1];
 73         }
 74     }
 75     chutimu(str,zhengquedaan);
 76 }
 77 
 78 public static void chutimu(String str,int zhengquedaan)
 79 {
 80     if(ccount<sj.N)
 81     {
 82         arr[ccount]=str;
 83         zqda[ccount]=zhengquedaan;
 84         System.out.println(arr[ccount]+"=");
 85         int daan;
 86         Scanner sc = new Scanner(System.in);
 87         daan = sc.nextInt(); 
 88         if(daan!=zhengquedaan)
 89         {
 90             System.out.println("答案错误");
 91             cishu[ccount]=1;
 92             cuoticount++;
 93         }
 94         else
 95         {
 96             System.out.println("答案正确");
 97             cishu[ccount]=0;
 98         }
 99         ccount++;
100         chuti();
101     }
102     else
103     {
104         System.out.println("错误率"+cuoticount*100/sj.N+"%");
105      
106     }
107 }
108 public static void  jixun()
109 {
110     System.out.println("请选择:   "+"\n"+
111                        "1.错题重做 "+"\n"+
112                        "2.再练一套 "+"\n"+
113                        "3.退出系统");
114      Scanner sc = new Scanner(System.in);
115      int xuan;
116      xuan = sc.nextInt();
117      switch(xuan)
118      {
119       case 1:cuoti();break;
120       case 2:zailian();break;
121       case 3:System.out.println("系统已退出,欢迎下次使用!");
122               System.exit(0);
123      }
124 }
125 //做错题
126 public static void cuoti()
127 {
128     nnum=cuoticount;
129     cuoticount=0;
130     for(int i=0;i<sj.N;i++)
131     {
132         if(cishu[i]==1)
133         {
134             System.out.println(arr[i]+"=");
135             Scanner sc = new Scanner(System.in);
136             int da;
137             da = sc.nextInt(); 
138             if(da!=zqda[i])
139             {
140                 System.out.println("答案错误");
141                 cuoticount++;
142             }
143             else
144             {
145                 cishu[i]=0;
146                 System.out.println("答案正确");
147             }
148         }
149     }
150     System.out.println("错误率"+cuoticount*100/nnum+"%");
151     jixun();
152 }
153 //再练
154 public static void zailian()
155 {
156     ccount=0;
157     cuoticount=0;
158     nnum=0;
159     chuti();
160 }
161 }

二年级+三年级+四年级

package pk1;
import java.util.*;
import java.util.Scanner;
public class Second {
    public static void second() {

     Scanner scan =new Scanner(System.in);
    ShuJu sj ;
    InTo.chuti();}}



package pk1;

import java.util.Scanner;

public class Third {
    public static void third() {
        
         Scanner scan =new Scanner(System.in);
        ShuJu sj ;
        
        InTo.chuti();}}





package pk1;

import java.util.Scanner;

public class Fourth {
    public static void fourth() {
        
         Scanner scan =new Scanner(System.in);
        ShuJu sj ;
        
        InTo.chuti();}}

 

posted @ 2021-10-09 20:17  zrswheart  阅读(37)  评论(0编辑  收藏  举报