PackageTest;ImportJava.io.BufferedReader;ImportJava.io.InputStreamReader;ImportJava.util.Scanner; Public classSizeyunsuan { Public Static voidMain (string[] args) {String condition= ""; intx, y; String Z, P,P1; Scanner INR=NewScanner (system.in); BufferedReader in=NewBufferedReader (NewInputStreamReader (system.in)); Do{System.out.print ("Please enter the first number:") ; while(true) { Try{p=In.readline (); X=Integer.parseint (P); if(x>-1000| | x<1000) {System.out.println ("\ n") ; } Break; } Catch(Exception e) {System.out.println ("\ n Error") ; }} System.out.print ("Please enter a second number:") ; while(true) { Try{P1=In.readline (); Y=Integer.parseint (p1); if(y>-1000| | y<1000) {System.out.println ("\ n") ; } Break; } Catch(Exception e) {System.out.println ("\ n Error") ; }} System.out.println ("Please enter operator (+,-, *,/):"); Z=Inr.nextline (); System.out.println ("\ n" +x+ "" +z+ "" +y+ "="); Core Test=Newcore (); Test.yunsuan (z, x, y); System.out.print ("Do you want to continue?" Y: Continue, any character: End "); Condition=Inr.nextline (); } while("Y". Equals (condition)); }}
PackageTest; Public classCore { Public voidYunsuan (String cc,DoubleADoubleb) {js test1=NewJS (); if(Cc.equals ("+") {Test1.jia (A, b); } Else if(Cc.equals ("-") {Test1.jian (A, b); } Else if(Cc.equals ("*") {Test1.cheng (A, b); } Else if(Cc.equals ("/")) { if(b! = 0) {Test1.chu (A, b); } Else{System.out.println ("Dividend can't be 0!" "); Throw NewArithmeticException (); } } Else{System.out.println ("Operator does not match! "); } }}
PackageTest; Public classJS {/** * @paramargs*/ Public Static DoubleJiaDoubleADoubleb) {DoubleResult=0; Result=a+b; System.out.println (A+"+"+b); SYSTEM.OUT.PRINTLN (result); returnresult; } Public Static DoubleJianDoubleADoubleb) {DoubleResult=0; Result=a-b; System.out.println (A+"-"+b); SYSTEM.OUT.PRINTLN (result); returnresult; } Public Static DoubleChengDoubleADoubleb) {DoubleResult=0; Result=a*b; System.out.println (A+"*"+b); SYSTEM.OUT.PRINTLN (result); returnresult; } Public Static DoubleChuDoubleADoubleb) {DoubleResult=0; Result=a/b; System.out.println (A+"/"+b); SYSTEM.OUT.PRINTLN (result); returnresult; }}
PackageTest;Import Staticorg.junit.assert.*;Importorg.junit.Test; Public classjstest {@Test Public voidtestJia1 () {DoubleA; JS Test2=NewJS (); A=js.jia (5,2); } @Test Public voidTestJian1 () {Doubleb; JS Test2=NewJS (); b=js.jian (10,1); } @Test Public voidTestChen1 () {DoubleC; JS Test2=NewJS (); C=js.cheng (8,3); } @Test Public voidtestChu1 () {DoubleD; JS Test2=NewJS (); D=js.chu (6,2); }}
My little buddy. 06 Liu Zehao http://www.cnblogs.com/wsnd/
Job 5.2