Loading

9.16课堂测试

 

  1 import java.util.Scanner;
  2 import java.util.ArrayList;
  3 import java.util.Random;
  4 import java.math.BigInteger;
  5 
  6 
  7 public class Calculates {
  8     static int n1;
  9     static int n2;
 10     static BigInteger n3;
 11     static ArrayList<String> eq = new ArrayList<>();
 12     public static void main(String[] args) {
 13 
 14        
 15         Getit();
 16         Makenums(n1, n2, n3);
 17         error(n1);
 18        
 19         }
 20         public static void Getit(){
 21             int num1,num2;
 22             BigInteger num3;
 23             Scanner sc = new Scanner(System.in);
 24             System.out.println("请输入出题的个数:");
 25             num1 = sc.nextInt();
 26             System.out.println("请输入操作数的个数:");
 27             num2 = sc.nextInt();
 28             System.out.println("请确定操作数的范围:");
 29             num3 = sc.nextBigInteger();
 30             n1=num1;n2=num2;n3=num3;
 31         }
 32         //判重
 33         public static int Judgesame(ArrayList<String> str, String s) {
 34         int num = 0;
 35         for (int i = 0; i < str.size(); i++) {
 36             if(s.equals(str.get(i))) {
 37                 num++;
 38                 break;
 39             }
 40         }
 41         if(num == 0) {
 42             str.add(s);
 43             return 1;
 44         }else {
 45             return 0;
 46             }
 47         }
 48         //出题
 49         public static void Makenums(int nu1,int nu2,BigInteger nu3){
 50             Random rand = new Random();
 51             Scanner sc = new Scanner(System.in);
 52             ArrayList<String> st = new ArrayList<>();
 53             double sum=0;
 54            
 55             BigInteger []numbers = new BigInteger[nu2];
 56             int []dsymbol = new int[nu2-1];
 57             String []symbol = new String[nu2-1];
 58            
 59 
 60             for(int i=0;i<nu1;i++){
 61 
 62                 for(int j=0;j<nu2;j++){
 63                     int MAX = 10;
 64                     byte[] b = new byte[MAX];
 65                     rand.nextBytes(b);
 66                     BigInteger bigInt = new BigInteger(b);
 67                     bigInt = bigInt.abs();
 68                     numbers[j] = bigInt;
 69                 }
 70                 for(int k=0;k<(nu2-1);k++){
 71                     dsymbol[k] = rand.nextInt(4);
 72                     switch (dsymbol[k]) {
 73                         case 0:
 74                             symbol[k] = "+";
 75                             break;
 76                         case 1:
 77                             symbol[k] = "-";
 78                             break;
 79                         case 2:
 80                             symbol[k] = "*";
 81                             break;
 82                         case 3:
 83                             symbol[k] = "/";
 84                             break;
 85                     }
 86                 }
 87                 StringBuffer strB = new StringBuffer();
 88                 for(int e=0;e<nu2;e++){
 89                     if(e==nu2-1){
 90                         strB.append(numbers[e]);
 91                     }else{
 92                         strB.append(numbers[e]).append(symbol[e]);
 93                     }
 94                 }
 95                 if(i==0) {
 96                     st.add(strB.toString());
 97                     System.out.println(st.get(i) + "=");
 98                     BigInteger answer1;
 99                     answer1 = sc.nextBigInteger();
100                     if(Judgeanswer(numbers, symbol, answer1, n2)){
101                         System.out.println("正确");
102                         sum++;
103                     }else{
104                         System.out.println("错误");
105                         eq.add(strB.toString());
106                     }
107                 }else {
108                     int judge = Judgesame(st, strB.toString());
109                     if (judge == 1) {
110        
111                         System.out.println(st.get(i) + "=");
112                         BigInteger answer2;
113                         answer2 = sc.nextBigInteger();
114                         if(Judgeanswer(numbers, symbol, answer2, n2)){
115                             System.out.println("正确");
116                             sum++;
117                         }else{
118                             System.out.println("错误");
119                             eq.add(strB.toString());
120                         }
121                     }
122                 }
123 
124             }
125             double correct = sum/nu1;
126             System.out.println("正确率为:"+correct);
127         }
128         //判断正误
129         public static boolean Judgeanswer(BigInteger num[],String sy[],BigInteger myanswer,int num2){
130            
131             BigInteger truth=new BigInteger("0");
132             truth = truth.add(num[0]);
133             for(int e=0;e<(num2-1);e++){
134                 for(int l=1;l<num2;l++){
135                     if(sy[e] == "+"){
136                         truth = truth.add(num[l]);
137                     }
138                     else if(sy[e] == "-"){
139                         truth = truth.subtract(num[l]);
140                     }
141                     else if(sy[e] == "*"){
142                         truth = truth.multiply(num[l]);
143                     }
144                     else if(sy[e] == "/"){
145                         truth = truth.divide(num[l]);
146                     }
147                 }
148             }
149             if(myanswer == truth){
150                 return true;
151             }
152             else{
153                 return false;
154             }
155         }
156         public static void error(int nu1){
157             System.out.println("错题如下");
158             for(int i=0;i<nu1;i++){
159                 System.out.println(eq.get(i) + "=");
160             }
161         }
162     }
163    这个是超大数
164 下面是精确数,实际上偷了一个懒,没有写在一个里面
165 
166 import java.util.Scanner;
167 import java.util.ArrayList;
168 import java.util.Random;
169 import java.math.BigDecimal;
170 
171 
172 
173 public class Calculate2 {
174     static int n1;
175     static int n2;
176     static BigDecimal n3;
177     static ArrayList<String> eq = new ArrayList<>();
178     public static void main(String[] args) {
179 
180        
181         Getit();
182         Makenums(n1, n2, n3);
183         error(n1);
184        
185         }
186         public static void Getit(){
187             int num1,num2;
188             BigDecimal num3;
189             Scanner sc = new Scanner(System.in);
190             System.out.println("请输入出题的个数:");
191             num1 = sc.nextInt();
192             System.out.println("请输入操作数的个数:");
193             num2 = sc.nextInt();
194             System.out.println("请确定操作数的范围:");
195             num3 = sc.nextBigDecimal();
196             n1=num1;n2=num2;n3=num3;
197         }
198         //判重
199         public static int Judgesame(ArrayList<String> str, String s) {
200         int num = 0;
201         for (int i = 0; i < str.size(); i++) {
202             if(s.equals(str.get(i))) {
203                 num++;
204                 break;
205             }
206         }
207         if(num == 0) {
208             str.add(s);
209             return 1;
210         }else {
211             return 0;
212             }
213         }
214         //出题
215         public static void Makenums(int nu1,int nu2,BigDecimal nu3){
216             Random rand = new Random();
217             Scanner sc = new Scanner(System.in);
218             ArrayList<String> st = new ArrayList<>();
219             double sum=0;
220            
221             BigDecimal []numbers = new BigDecimal[nu2];
222             int []dsymbol = new int[nu2-1];
223             String []symbol = new String[nu2-1];
224            
225 
226             for(int i=0;i<nu1;i++){
227 
228                 for(int j=0;j<nu2;j++){
229                     float maxF = nu3.floatValue();
230                     BigDecimal Int = new BigDecimal(Math.random() * (maxF - 0) + 0);
231                     // BigDecimal bigInt = new BigDecimal(b);
232                     // bigInt = bigInt.abs();
233                     numbers[j] = Int;
234                 }
235                 for(int k=0;k<(nu2-1);k++){
236                     dsymbol[k] = rand.nextInt(4);
237                     switch (dsymbol[k]) {
238                         case 0:
239                             symbol[k] = "+";
240                             break;
241                         case 1:
242                             symbol[k] = "-";
243                             break;
244                         case 2:
245                             symbol[k] = "*";
246                             break;
247                         case 3:
248                             symbol[k] = "/";
249                             break;
250                     }
251                 }
252                 StringBuffer strB = new StringBuffer();
253                 for(int e=0;e<nu2;e++){
254                     if(e==nu2-1){
255                         strB.append(numbers[e]);
256                     }else{
257                         strB.append(numbers[e]).append(symbol[e]);
258                     }
259                 }
260                 if(i==0) {
261                     st.add(strB.toString());
262                     System.out.println(st.get(i) + "=");
263                     BigDecimal answer1;
264                     answer1 = sc.nextBigDecimal();
265                     if(Judgeanswer(numbers, symbol, answer1, n2)){
266                         System.out.println("正确");
267                         sum++;
268                     }else{
269                         System.out.println("错误");
270                         eq.add(strB.toString());
271                     }
272                 }else {
273                     int judge = Judgesame(st, strB.toString());
274                     if (judge == 1) {
275        
276                         System.out.println(st.get(i) + "=");
277                         BigDecimal answer2;
278                         answer2 = sc.nextBigDecimal();
279                         if(Judgeanswer(numbers, symbol, answer2, n2)){
280                             System.out.println("正确");
281                             sum++;
282                         }else{
283                             System.out.println("错误");
284                             eq.add(strB.toString());
285                         }
286                     }
287                 }
288 
289             }
290             double correct = sum/nu1;
291             System.out.println("正确率为:"+correct);
292         }
293         //判断正误
294         public static boolean Judgeanswer(BigDecimal num[],String sy[],BigDecimal myanswer,int num2){
295            
296             BigDecimal truth=new BigDecimal("0");
297             truth = truth.add(num[0]);
298             for(int e=0;e<(num2-1);e++){
299                 for(int l=1;l<num2;l++){
300                     if(sy[e] == "+"){
301                         truth = truth.add(num[l]);
302                     }
303                     else if(sy[e] == "-"){
304                         truth = truth.subtract(num[l]);
305                     }
306                     else if(sy[e] == "*"){
307                         truth = truth.multiply(num[l]);
308                     }
309                     else if(sy[e] == "/"){
310                         truth = truth.divide(num[l]);
311                     }
312                 }
313             }
314             if(myanswer == truth){
315                 return true;
316             }
317             else{
318                 return false;
319             }
320         }
321         public static void error(int nu1){
322             System.out.println("错题如下");
323             for(int i=0;i<nu1;i++){
324                 System.out.println(eq.get(i) + "=");
325             }
326         }
327     }

 

   
   
   
   
   
posted @ 2022-09-20 12:55  冰稀饭Aurora  阅读(11)  评论(0编辑  收藏  举报