My teammates: Du Yinhao 201306114426
Size.java
ImportJava.util.*;ImportJava.util.Random;ImportJava.text.DecimalFormat; Public classSiZe {Static intnum_2 = 0; Public Static voidMain (string[] args) {DecimalFormat Dformat=NewDecimalFormat ("#.00"); while(Num_2 > 5 | | num_2 <= 0) {System.out.print ("Please enter the number of questions (the maximum number of topics cannot exceed 5):"); Scanner SC=NewScanner (system.in); Num_2=Sc.nextint (); } System.out.println (Note Division calculation results reserved two bits, including rounding!! "); FengZhuang FZ=NewFengZhuang (); } Public intHuoqu () {returnnum_2; }}
Fengzhuang.java
ImportJava.util.Random;ImportJava.util.Scanner;ImportJava.text.DecimalFormat; Public classFengZhuang {//static int num_1 = 0; PublicFengZhuang () {intNum_1 =size.num_2; String[] str_1=NewString[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; String[] str_2=NewString[] {"+", "-", "*", "/"}; intindex_1 = 0; intIndex_2 = 0; int[] A =New int[2]; Doubledata = 0; DoubleAnswer = 0; intnum = 0; Longt1=System.currenttimemillis (); for(intk = 0; K < num_1; k++) {System.out.print ("First" + (k+1) + "question:"); for(inti = 0; I < 2; i++) {index_1=NewRandom (). Nextint (9); if(Str_2[index_2].equals ("/") && index_1! = 0) { while(Index_1 = = 0) {index_1=NewRandom (). Nextint (9); }} A[i]=index_1; if(I! = 1) {Index_2=NewRandom (). Nextint (4); } } /////////////System.out.print (str_1[a[0]]+str_2[index_2]+str_1[a[1]]+ "="); /////Scanner input =NewScanner (system.in); Data=input.nextdouble (); Switch(index_2) { Case0: Answer= A[0] + a[1]; Break; Case1: Answer= a[0]-a[1]; Break; Case2: Answer= a[0] * a[1]; Break; Case3: Answer= (Double) A[0]/a[1]; Answer= (Math.Round (answer*100)/100.0); Break; } if(Data = =answer) {System.out.println ("You entered the correct answer!" "); Num++; } Else{System.out.println ("The answer you entered is wrong!" The correct answer is: "+answer); } System.out.println (); if((System.currenttimemillis ()-t1)/1000 >= 120) {System.out.println ("The time has come, can't answer!"); Break; }} System.out.println (Num_1+ "Road title, you have a total answer to the" +num+ "road title! "); System.out.println ("+num+" is the time to complete the topic: "+ (System.currenttimemillis ()-t1)/1000 +" seconds! "); } }
Arithmetic--encapsulation