一、定义方法验证题目是否重复;并将出题参数用子方法定义。 2、定义随机数生成器子方法,根据出题参数(出题个数、操作数的个数、确定操作数的取值范围)生成全部的随机操作数。
阶段2: 1、定义方法实现在线答题;全部完成后,显示答题结果,输出正确率和错题。 2、定义方法实现错题集、错题重练并记录错题的次数功能。
1 package Test; 2 3 import java.util.Random; 4 import java.util.Scanner; 5 6 public class Math_4 { 7 static int n ; 8 static int fw ; 9 10 static char[] f = new char[100010]; 11 static int [] s1 = new int [100010]; 12 static int [] s2 = new int [100010]; 13 static int t = 0; 14 static int [] answer = new int [100010]; 15 static int [] ben = new int [100010]; 16 static int x = 0; 17 static int y = 0; 18 static int s = 1; 19 static Scanner sc = new Scanner(System.in); 20 public static void main(String[] args) { 21 22 Top(); 23 init(); 24 for(int i = 0 ; i< n ;i++) 25 { 26 x++; 27 Show(x); 28 } 29 Shownum(); 30 replay(); 31 32 } 33 public static void Top() 34 { 35 System.out.println("请输入一共输入多少个"); 36 n = sc.nextInt(); 37 System.out.println("请输入范围"); 38 fw=sc.nextInt(); 39 } 40 public static int random(int w) //随机数生成器 41 { 42 Random rm=new Random(); //随机数 43 44 return rm.nextInt(w) + 1; 45 } 46 public static void init() 47 { 48 for(int i = 0 ; i < n ; i ++) 49 { 50 t++; 51 //符号 52 int number_3; 53 number_3 = random(4); 54 //数字 55 int number_1 = random(fw); 56 int number_2 = random(fw); 57 s1[t] = number_1 ; 58 s2[t] = number_2 ; 59 60 if(number_3==1) 61 { 62 f[t] = '+'; 63 answer[s++] = number_1 + number_2; 64 } 65 else if(number_3==2) 66 { 67 f[t] = '-'; 68 answer[s++] = number_1 - number_2; 69 } 70 else if (number_3==3) 71 { 72 f[t] = '*'; 73 answer[s++] = number_1 * number_2; 74 } 75 else if(number_3==4) 76 { 77 f[t] = '/'; 78 answer[s++] = number_1 / number_2; 79 } 80 } 81 } 82 public static void Show(int x) 83 { 84 System.out.print(s1[x]); 85 86 if(f[x] == '+') 87 { 88 89 System.out.print("+"); 90 } 91 else if(f[x] == '-') 92 { 93 94 System.out.print( "-" ); 95 } 96 else if (f[x] == '*') 97 { 98 99 System.out.print( "*" ); 100 } 101 else if(f[x] == '/') 102 { 103 104 System.out.print( "/" ); 105 } 106 107 System.out.print(s2[x]); 108 System.out.println( "=\t\t" ); 109 int d = sc.nextInt(); 110 if(d != answer[x]) 111 { 112 System.out.println( "答案错误" ); 113 ben[y++] = x; 114 } 115 } 116 public static void replay() 117 { 118 System.out.println("错题本重练系统"); 119 for(int i = 0 ; i < y ;i++) 120 { 121 Show(ben[i]); 122 } 123 } 124 public static void Shownum() 125 { 126 System.out.println("错题个数: " + y); 127 int b = (n-y)*10/n*10; 128 int d = b + (n-y)*10%n*10/n; 129 System.out.println("正确率: " + d + "%" ); 130 131 } 132 }
阶段三 3、 改造程序,可以实现浮点数精确计算。 可以实现无限大的整数的计算。
1 package Test; 2 3 import java.math.BigInteger; 4 import java.util.Random; 5 import java.util.Scanner; 6 7 public class Math_5 { 8 static int n ; 9 static int flag ; 10 static int fw ; 11 12 static char[] f = new char[100010]; 13 static double [] s1 = new double [100010]; 14 static double [] s2 = new double [100010]; 15 static BigInteger [] s3 = new BigInteger [100010]; 16 static BigInteger [] s4 = new BigInteger [100010]; 17 18 static int t = 0; 19 static double [] answer = new double [100010]; 20 static int [] ben = new int [100010]; 21 static BigInteger [] answer1 = new BigInteger [100010]; 22 23 static int x = 0; 24 static int y = 0; 25 static int s = 1; 26 static Scanner sc = new Scanner(System.in); 27 public static void main(String[] args) { 28 29 Top(); 30 if(flag == 1) 31 { 32 init1(); 33 for(int i = 0 ; i< n ;i++) 34 { 35 x++; 36 Show(x); 37 } 38 Shownum(); 39 replay(); 40 } 41 else if (flag == 2) 42 { 43 init2(); 44 for(int i = 0 ; i< n ;i++) 45 { 46 x++; 47 Show2(x); 48 } 49 Shownum(); 50 replay2(); 51 } 52 53 } 54 public static void Top() 55 { 56 System.out.println("请输入一共输入题目个数"); 57 n = sc.nextInt(); 58 59 System.out.println("请输入浮点数: 1 ; 大整数: 2"); 60 flag=sc.nextInt(); 61 System.out.println("请输入数字范围"); 62 if(flag == 2) 63 { 64 BigInteger big; 65 big=sc.nextBigInteger(); 66 } 67 else 68 fw=sc.nextInt(); 69 } 70 71 public static double random1(int w) //随机浮点数生成器 72 { 73 Random rm=new Random(); //随机数 74 75 return rm.nextDouble(w) + 1; 76 } 77 public static int random(int w) //随机数生成器 78 { 79 Random rm=new Random(); //随机数 80 81 return rm.nextInt(w) + 1; 82 } 83 public static void init1() //浮点数生成 84 { 85 for(int i = 0 ; i < n ; i ++) 86 { 87 t++; 88 //符号 89 int number_3; 90 number_3 = random(4); 91 //数字 92 double number_1 = random1(fw); 93 double number_2 = random1(fw); 94 s1[t] = number_1 ; 95 s2[t] = number_2 ; 96 97 if(number_3==1) 98 { 99 f[t] = '+'; 100 answer[s++] = Arith.add(number_1, number_2); 101 } 102 else if(number_3==2) 103 { 104 f[t] = '-'; 105 answer[s++] = Arith.sub(number_1 , number_2); 106 } 107 else if (number_3==3) 108 { 109 f[t] = '*'; 110 answer[s++] =Arith.mul(number_1 , number_2); 111 } 112 else if(number_3==4) 113 { 114 f[t] = '/'; 115 answer[s++] = Arith.div(number_1 , number_2); 116 } 117 } 118 } 119 public static void init2() //大整数生成 120 { 121 for(int i = 0 ; i < n ; i ++) 122 { 123 t++; 124 //符号 125 int number_3; 126 number_3 = random(4); 127 //数字 128 129 System.out.println("输入题目"); 130 BigInteger n1 = sc.nextBigInteger(); 131 BigInteger n2 = sc.nextBigInteger(); 132 s3[t] = n1 ; 133 s4[t] = n2 ; 134 135 if(number_3==1) 136 { 137 f[t] = '+'; 138 answer1[s++] = n1.add(n2); 139 } 140 else if(number_3==2) 141 { 142 f[t] = '-'; 143 answer1[s++] = n1.subtract(n2); 144 } 145 else if (number_3==3) 146 { 147 f[t] = '*'; 148 answer1[s++] = n1.multiply(n2); 149 } 150 else if(number_3==4) 151 { 152 f[t] = '/'; 153 answer1[s++] = n1.divide(n2); 154 } 155 } 156 } 157 public static void Show(int x) //显示浮点数 158 { 159 System.out.print(s1[x]); 160 161 if(f[x] == '+') 162 { 163 164 System.out.print("+"); 165 } 166 else if(f[x] == '-') 167 { 168 169 System.out.print( "-" ); 170 } 171 else if (f[x] == '*') 172 { 173 174 System.out.print( "*" ); 175 } 176 else if(f[x] == '/') 177 { 178 179 System.out.print( "/" ); 180 } 181 182 System.out.print(s2[x]); 183 System.out.println( "=\t\t" ); 184 System.out.println( "输入答案: 保留小数点后14位" ); 185 double d = sc.nextDouble(); 186 if(d != answer[x]) 187 { 188 System.out.println( "答案错误" ); 189 System.out.println( "正确答案: " + answer[x]); 190 ben[y++] = x; 191 } 192 } 193 public static void Show2(int x) //显示大整数 194 { 195 System.out.print(s3[x].toString()); 196 197 if(f[x] == '+') 198 { 199 200 System.out.print("+"); 201 } 202 else if(f[x] == '-') 203 { 204 205 System.out.print( "-" ); 206 } 207 else if (f[x] == '*') 208 { 209 210 System.out.print( "*" ); 211 } 212 else if(f[x] == '/') 213 { 214 215 System.out.print( "/" ); 216 } 217 218 System.out.print(s4[x].toString()); 219 System.out.println( "=\t\t" ); 220 BigInteger d = sc.nextBigInteger(); 221 if(d != answer1[x]) 222 { 223 System.out.println( "答案错误" ); 224 System.out.println( "正确答案: " + answer1[x].toString()); 225 ben[y++] = x; 226 } 227 } 228 public static void replay() //浮点数重练 229 { 230 System.out.println("错题本重练系统"); 231 for(int i = 0 ; i < y ;i++) 232 { 233 Show(ben[i]); 234 } 235 } 236 public static void replay2() //大整数重练 237 { 238 System.out.println("错题本重练系统"); 239 for(int i = 0 ; i < y ;i++) 240 { 241 Show2(ben[i]); 242 } 243 } 244 public static void Shownum() //统计正确率 245 { 246 System.out.println("错题个数: " + y); 247 int b = (n-y)*10/n*10; 248 int d = b + (n-y)*10%n*10/n; 249 System.out.println("正确率: " + d + "%" ); 250 251 } 252 }
标签:int,四则运算,number,System,++,static,测试,课堂,out From: https://www.cnblogs.com/fan-wang/p/16704371.html