No.1 四则运算题目生成程序(基于控制台)
需求分析:
能够根据用户自身对题目数量的需求自动生成一定数量的包含分数的四则运算题目的命令行程序。
功能设计:
设计实现:
程序是用Java实现的,主要有四个类,Compute用来处理分数及整数的计算过程,Answer将用户输入的答案同正确答案进行比较来判断对错,Test进行正确率的计算,Frac进行分数的生成及化简
代码说明:
(1)分数的生成,包括生成分子,分母,以及两者结合的分数
public class Frac { private int Zi; private int Mu; private String frac; }
(2)进行生成题数以及生成数字大小的设定。
public static void main(String[] args) { Frac f1 = new Frac(); Frac f2 = new Frac(); int m; int com; int r=0,w=0; String a2; Scanner a1 = new Scanner(System.in); Compute c = new Compute(); System.out.println("How many topic do you want?"); int i = a1.nextInt(); Scanner sc = new Scanner(System.in); Scanner a3 = new Scanner(System.in); System.out.println("Please enter a range:"); m = a3.nextInt(); for (int j = 0; j < i; j++) { f1.createfrac(m); f2.createfrac(m); com = (int) (Math.random() * 4 + 1); }
(3)将用户输入的数据同正确答案进行比较,如果有错,需给出正确答案。
static boolean compare(String a, String b) { if (a.equals(b)) {System.out.println("Good, you are right!"); return true;} else { System.out.println("You are wrong..the right answer is " + b); return false; } } }
运行结果:

PSP:
| PSP2.1 | Personal Software Process Stages | Time (min) Senior Student | Time (min) | 
| Planning | 计划 | 10 | 15 | 
| · Estimate | 估计这个任务需要多少时间 | 30 | 40 | 
| Development | 开发 | 70 | 80 | 
| · Analysis | 需求分析 (包括学习新技术) | 20 | 30 | 
| · Design Spec | 生成设计文档 | 10 | 15 | 
| · Design Review | 设计复审 | 0 | 0 | 
| · Coding Standard | 代码规范 | 10 | 15 | 
| · Design | 具体设计 | 20 | 25 | 
| · Coding | 具体编码 | 90 | 120 | 
| · Code Review | 代码复审 | 5 | 5 | 
| · Test | 测试(自我测试,修改代码,提交修改) | 10 | 10 | 
| Reporting | 报告 | 10 | 15 | 
| · | 测试报告 | 5 | 3 | 
| · | 计算工作量 | 3 | 5 | 
| · | 并提出过程改进计划 | 5 | 0 | 
码市链接:
https://coding.net/u/watermelon123/p/homework1/git
小结:
由于自己在之前的学习过程中缺乏动手实践的能力,所以这个程序对我来说很有难度,在程序设计的过程中遇到了不少的困难。借助百度以及同学的解答,部分问题得到了解决,但还是有很多的不足,希望在往后的实验当中能通过实践不断提高自己的编程能力。
原文:http://www.cnblogs.com/ws002/p/6516264.html