一個命令行程序實現:java
統計正確率git
法則:框架
產品代碼主要進行三個方面的測試:dom
而後再有一個類做爲錯誤判斷測試輸出。測試
import java.util.Random; public class Output { private int a, b; private int i; private String operator[]={"+","-","×","÷"}; public Output(){ while(true){ a=new Random().nextInt(100); b=new Random().nextInt(100); i=new Random().nextInt(4); if(i==1&&a<b){ continue; } if(i==3){ if(b==0){ continue; } if(a%b!=0){ continue; } } break; } } public String getString(){ return new String(a+operator[i]+b+"="); } public boolean panduan(String s){ int i,result = 0; try{ i=Integer.valueOf(s).intValue(); }catch(Exception e){ return false; } switch(this.operator().toCharArray()[0]){ case '+':result=this.getA()+this.getB();break; case '-':result=this.getA()-this.getB();break; case '×':result=this.getA()*this.getB();break; case '÷':result=this.getA()/this.getB();break; } if(result==i){ return true; }return false; } public String operator(){ return operator[this.i]; } public int getA() { return a; } public int getB() { return b; } }
搭檔:20165231王楊鴻永this
起初看到四則運算我一位只是作一個簡易的計算器,當打開要求發現事情並無那麼簡單。而後就開始各類思考參考,想出相似於僞代碼的一個框架,按照框架一步步實現,可是因爲能力和學識的限制不少功能並不能很好的實現,或者無法實現沒作出來。目前出來的算是勉強能夠看的結果吧。後續還會接着改進。命令行