一个命令行程序实现: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
起初看到四则运算我一位只是作一个简易的计算器,当打开要求发现事情并无那么简单。而后就开始各类思考参考,想出相似于伪代码的一个框架,按照框架一步步实现,可是因为能力和学识的限制不少功能并不能很好的实现,或者无法实现没作出来。目前出来的算是勉强能够看的结果吧。后续还会接着改进。命令行