吴东益 201421123115、李志霖 201421123116
代码地址:https://git.coding.net/w201421123115/jiedui2.git
a. 需求分析:
1.通过单元测试,测试加减乘除功能。
2.通过单元测试代码,测试计算类对于各种参数的支持:
a. 输入是有错误的,例如 “1 ++ 2”,
b. 在数值范围是 -1000 .. 1000 的时候,传进去 “10000 + 32768”,
c. 或者是 “ 248 / 0” 怎么办?
d. 怎么告诉函数的调用者 “你错了”? 把返回的字符串定义为 “-1” 来表示?
e. 那么如果真的计算结果是 “-1” 又怎么处理呢?
b.计算代码:
// 加法计算
public static String addtion(Fractions fractions1, Fractions fractions2) {
Fractions result = new Fractions();
int result_numerator, min; // 相加后的分子以及两分数分母的最小公倍数
min = Fractions.minCommonMultiple(fractions1.getDenominator(), fractions2.getDenominator());
result_numerator = (min / fractions1.getDenominator()) * fractions1.getNumerator()
+ (min / fractions2.getDenominator()) * fractions2.getNumerator();
result.setValue(result_numerator, min);
return result.getFraction();
}
public static String addtion(Fractions fractions1, int i) {
Fractions result = new Fractions();
int result_numerator; // 相加后的分子
result_numerator = fractions1.getNumerator() + i * fractions1.getDenominator();
result.setValue(result_numerator, fractions1.getDenominator());
return result.getFraction();
}
public static String addtion(int i, Fractions fractions2) {
Fractions result = new Fractions();
int result_numerator; // 相加后的分子
result_numerator = fractions2.getNumerator() + i * fractions2.getDenominator();
result.setValue(result_numerator, fractions2.getDenominator());
return result.getFraction();
}
// 减法计算
public static String subtraction(Fractions fractions1, Fractions fractions2) {
Fractions result = new Fractions();
int result_numerator, min; // 相减后的分子以及两分数分母的最小公倍数
min = Fractions.minCommonMultiple(fractions1.getDenominator(), fractions2.getDenominator());
result_numerator = (min / fractions1.getDenominator()) * fractions1.getNumerator()
- (min / fractions2.getDenominator()) * fractions2.getNumerator();
result.setValue(result_numerator, min);
return result.getFraction();
}
public static String subtraction(Fractions fractions1, int i) {
Fractions result = new Fractions();
int result_numerator; // 相减后的分子
result_numerator = fractions1.getNumerator() - i * fractions1.getDenominator();
result.setValue(result_numerator, fractions1.getDenominator());
return result.getFraction();
}
public static String subtraction(int i, Fractions fractions1) {
Fractions result = new Fractions();
int result_numerator; // 相减后的分子
result_numerator = i * fractions1.getDenominator() - fractions1.getNumerator();
result.setValue(result_numerator, fractions1.getDenominator());
return result.getFraction();
}
// 乘法计算
public static String multiplication(Fractions fractions1, Fractions fractions2) {
Fractions result = new Fractions();
int result_numerator, result_denominator; // 相乘后的分子和分母
result_numerator = fractions1.getNumerator() * fractions2.getNumerator();
result_denominator = fractions1.getDenominator() * fractions2.getDenominator();
result.setValue(result_numerator, result_denominator);
return result.getFraction();
}
public static String multiplication(Fractions fractions1, int i) {
Fractions result = new Fractions();
int result_numerator; // 相乘后的分子
result_numerator = fractions1.getNumerator() * i;
result.setValue(result_numerator, fractions1.getDenominator());
return result.getFraction();
}
public static String multiplication(int i, Fractions fractions1) {
Fractions result = new Fractions();
int result_numerator; // 相乘后的分子
result_numerator = fractions1.getNumerator() * i;
result.setValue(result_numerator, fractions1.getDenominator());
return result.getFraction();
}
// 除法计算
public static String division(Fractions fractions1, Fractions fractions2) {
Fractions result = new Fractions();
int result_numerator, result_denominator; // 相除后的分子和分母
// 分数相除问题转换成分数相乘问题
result_numerator = fractions1.getNumerator() * fractions2.getDenominator();
result_denominator = fractions1.getDenominator() * fractions2.getNumerator();
result.setValue(result_numerator, result_denominator);
return result.getFraction();
}
public static String division(Fractions fractions1, int i) {
Fractions result = new Fractions();
int result_denominator; // 相除后的分母
// 分数相除问题转换成分数相乘问题
result_denominator = fractions1.getDenominator() * i;
result.setValue(fractions1.getNumerator(), result_denominator);
return result.getFraction();
}
public static String division(int i,Fractions fractions1) {
Fractions result = new Fractions();
int result_numerator,result_denominator; // 相除后的分子和分母
// 分数相除问题转换成分数相乘问题
result_denominator = fractions1.getNumerator();
result_numerator=fractions1.getDenominator()*i;
result.setValue(result_numerator, result_denominator);
return result.getFraction();
}
public static String division(int i,int j) {
Fractions result = new Fractions();
result.setValue(i,j);
return result.getFraction();
}
}
c.实验截图:
d.结对照片:
e.实验小结:
在实验开始阶段,由于个人疏忽,对题目理解错误,忽视了代码覆盖率这一要点,在发现之后在原代码上测试多次仍然存在问题,就运用之前的四则运算进行了一下测试才勉强成功。在之后的作业里要做到认真审题,避免这次的错误再次发生。
f.psp:
PSP2.1 | Personal Software Process Stages | Time Senior Student | Time |
Planning | 计划 | 0.5h | 15min |
· Estimate | 估计这个任务需要多少时间 | 3h | 2.5h |
Development | 开发 | 1h | 1h |
· Analysis | 需求分析 (包括学习新技术) | 15min | 8min |
· Design Spec | 生成设计文档 | 5min | 5min |
· Design Review | 设计复审 | 15min | 15min |
· Coding Standard | 代码规范 | 5min | 5min |
· Design | 具体设计 | 10min | 10min |
· Coding | 具体编码 | 35min | 20min |
· Code Review | 代码复审 | 5min | 5min |
· Test | 测试(自我测试,修改代码,提交修改) | 15min | 20min |
Reporting | 报告 | 10min | 10min |