1.改进现有代码
博客链接
201521123017
201521123015码云:
使用图形界面实现四则运算
四则运算优化类图
JUnit单元测试
运行截图
- 四则运算优化
- 使用图形界面实现四则运算
2.功能改进与扩展
乘方
if(s.indexOf("^")>-1){ int i=s.indexOf("^"); if(s.indexOf("^",i+1)==i+1){ throw new IllegalArgumentException("Input error! Don‘t like 1++1");//格式错误时抛出异常 }else{ power(s); } }//用于检测是否为乘方
public void power(String s)//乘方 { String[] str=s.split("\\^"); int number=Integer.parseInt(str[1]); if(str[0].indexOf("/")>-1 )//分数 { String[] str1=str[0].split("[/]"); if(Integer.parseInt(str1[1]) != 0 )//分母不为零 { int a=1; int b=1; for(int i=0;i<number;i++){ a=a*Integer.parseInt(str1[0]); b=b*Integer.parseInt(str1[1]); } result=simplefraction(a,b); }else{ throw new IllegalArgumentException("Divisor cannot be zero!");//除数为零时抛出异常 } } else{//整数 if( Integer.parseInt(str[0])<1000&&Integer.parseInt(str[1])<1000&&Integer.parseInt(str[0])>-1000&&Integer.parseInt(str[1])>-1000) { int c=1; for(int i=0;i<number;i++){ c=c*Integer.parseInt(str[0]); } result = c+""; } else{ throw new IllegalArgumentException("overrun!");}//数值范围超出时抛出异常 } }
运行截图
- 通过“^”来判定是否为乘方运算,若是类似“1++1”,则抛出错误,若是公式无错,则进入运算,分两种情况:整数和真分数,通过for循环实现乘方运算。与java原有的乘方有所差异,头文件:#include
3.在两人合作的过程中, 请看下面的内容
- 代码风格规范和代码设计规范
码云提交记录
- 四则运算优化
- 使用图形界面实现四则运算
结对编程照片
- 测评
PSP2.1 | 个人开发流程 | 预估耗费时间(分钟) | 实际耗费时间(分钟) |
---|---|---|---|
Planning | 计划 | 10 | 15 |
· Estimate | 明确需求和其他相关因素,估计每个阶段的时间成本 | 10 | 12 |
Development | 开发 | 60 | 75 |
· Analysis | 需求分析 (包括学习新技术) | 10 | 20 |
· Design Spec | 生成设计文档 | 10 | 15 |
· Design Review | 设计复审 | 6 | 8 |
· Coding Standard | 代码规范 | 5 | 3 |
· Design | 具体设计 | 8 | 9 |
· Coding | 具体编码 | 40 | 45 |
· Code Review | 代码复审 | 5 | 4 |
· Test | 测试(自我测试,修改代码,提交修改) | 8 | 13 |
Reporting | 报告 | 7 | 8 |
. | 测试报告 | 3 | 2 |
. | 计算工作量 | 1 | 1 |
. | 并提出过程改进计划 | 3 | 3 |