用Java语言实现一个计算器程序
import java.io.*;
public class Calculator {
public static void main(String[] args) throws IOException{
BufferedReader b= new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入数字A:");
String A=b.readLine();
System.out.print("请输入数字B:");
String B=b.readLine();
int C=(new Integer(A)).intValue()/(new Integer(B).intValue());
System.out.print("结果是:"+C);
}
}
运行结果:
分析:
1.满足正确性;
2.用户出错,结果无法预料,所以不满足健壮性;
3.为专门问题制定,不满足可复用性;
4.增加一个功能,需要修改原来的类,违反开—闭原则,不满足可维护性;
5.程序简单,高效性不考虑。