Arithmetic--encapsulation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.