《个人开发流程》——计应191第三组王芳
一:需求分析:要设计一个四则运算练系的程序,随机产生100以内的加减乘除,在用户
给出答案后,系统给出正确答案,并给出用户的答案是否正确。
二:具体设计:
写一个实体类Size,并在其中写上所需要的方法,最后在main方法中输出自己的计算结果
三:具体代码:package examples01;
import java.math.BigDecimal;
import java.util.Random;
import java.util.Scanner;
public class Size {
static double sum = 0.0;
public static void main(String[] args) {
System.out.print("四则运算数目:");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int x, y, z, k1, k2;
Random ra = new Random();
for (int i = 0; i < n;) {
// 初始化
x = ra.nextInt(100);
k1 = ra.nextInt(4);
y = ra.nextInt(100);
k2 = ra.nextInt(4);
z = ra.nextInt(100);
// 计算 判断符号
if (k2 > 1 && k1 < 1) {
sum = Count(k2, y, z);
if (sum < 0)
continue;
Format();
sum = Count(k1, x, sum);
if (sum < 0)
continue;
Format();
System.out.print(x);
Print(k1);
System.out.print(y);
Print(k2);
System.out.println(z + "=" + sum);
} else {
sum = Count(k1, x, y);
if (sum < 0)
continue;
Format();
sum = Count(k2, sum, z);
if (sum < 0)
continue;
Format();
System.out.print(x);
Print(k1);
System.out.print(y);
Print(k2);
System.out.println(z + "=" + sum);
}
// 小学题 结果没有负数
if (sum >= 0)
i++;
}
}
// 判断符号并计算
private static double Count(int k, double x, double y) {
double s = 0.0;
if (k == 0) {
s = x + y;
} else if (k == 1) {
s = x - y;
} else if (k == 2) {
s = x * y;
} else if (k == 3) {
s = x / y;
}
return s;
}
// 打印运算符号
private static void Print(int k) {
switch (k) {
case 0:
System.out.print("+");
break;
case 1:
System.out.print("-");
break;
case 2:
System.out.print("*");
break;
case 3:
System.out.print("/");
break;
}
}
// 格式化double 最多保留小数点后两位
public static void Format() {
BigDecimal bd = new BigDecimal(sum);
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
sum = bd.doubleValue();
}
}
四:运算结果

五:psp(个人软件开发流程)
|
psp阶段 |
预估时间(分钟) |
实际时间(分钟) |
|
计划 |
10 |
30 |
|
明确需求和其它相关因素, 估计每个阶段的时间和成本 |
15 |
20 |
|
开发 |
240 |
360 |
|
需求分析 |
10 |
15 |
|
生成设计文档 |
20 |
30 |
|
设计复审(和同事审核设计文档) |
15 |
25 |
|
代码规范(为目前的开发制定合适的规范) |
15 |
30 |
|
具体设计 |
20 |
30 |
|
具体编码 |
130 |
160 |
|
代码复审 |
30 |
50 |
|
测试(自测、修改代码、提交 修改) |
10 |
20 |
|
报告 |
20 |
30 |
|
测试报告 |
15 |
20 |
|
计算工作量 |
5 |
5 |
|
事后总结,并提出过程改进计划 |
20 |
20 |
六:总结
在刚开始知道这个任务的时候,我在脑海里大致想了一下流程,感觉它应该不会太难写,但真的操作的时候,不是那里出问题就是这有问题,真的是让人很崩溃。而且自己的能力是很弱的,自能实现一些简单的功能,希望以后能加强改进一下。

浙公网安备 33010602011771号