结对编程-四则运算(挑战出题)
结对伙伴:20162307 张韵琪
需求分析
1.建立一个新的代码仓库用于储存代码
2.随机生成指定运算符个数、指定个数和指定存储路径的表达式,包括括号
3.根据要求进行编译测试
4.ps:操作数为个位整数,即选择范围只能是:1,2,3,4,5,6,7,8,9这9个数字
操作符选择范围只能是:+,-,*,/, 还有括号
设计思路(同时输出UML类图)
1.在之前的代码的基础上进行了修改,原来的代码不能生成括号,括号部分参考了百度上有关二叉树的部分
2.输出文件,这部分就在老师博客的基础上进行了修改
实现过程中的关键代码解释
运用循环产生表达式并输出到文件
Random rnd = new Random(); FileWriter fw = new FileWriter(file_path); BinaryTree bTree; for(int i = 0; i < num_topic ; i++){ bTree = new BinaryTree(optr_num ); bTree.createBTree(); System.out.println(bTree.toString() ); fw.write(bTree.toString() +'\n'); } fw.close();
生成运算符
public static char getOperator(){ char operator = 0; Random ran = new Random(); int i = ran.nextInt(4); switch(i){ case 0: operator = '+'; break; case 1: operator = '-'; break; case 2: operator = '*'; break; case 3: operator = '/'; break; } return operator; }
括号生成参考了二叉树生成
public String toString(){ String Lstr = "", Rstr = "", Str = ""; if(hasChild()){ if(getRchild().hasChild()){ //判断左邻括号的运算符是否为'/' if(str.equals("/")){ Rstr = getRchild().toString(); } //判断左邻括号的运算符是否为'*'或'-' else if(str.equals("*") || str.equals("-")){ //判断op是否为'+'或'-' if(getRchild().str.equals("+") || getRchild().str.equals("-")){ Rstr = getRchild().toString(); } else{ Rstr = getRchild().toString().substring(1, getRchild().toString().length()-1); } } else{ Rstr = getRchild().toString().substring(1, getRchild().toString().length()-1); } } else{ Rstr = getRchild().str; } if(getLchild().hasChild()){ if(str.equals("*") || str.equals("/")){ if(getLchild().str.equals("+") || getLchild().str.equals("-")){ Lstr = getLchild().toString(); } else{ Lstr = getLchild().toString().substring(1, getLchild().toString().length()-1); } } else{ Lstr = getLchild().toString().substring(1, getLchild().toString().length()-1); } } else{ Lstr = getLchild().str; } Str = "(" + Lstr + str + Rstr + ")"; } else{ Str = str; } return Str; }
测试方法
用exprchecker.exe
进行测试
运行过程截图
5个运算符
7个运算符
测试
代码托管地址
遇到的困难及解决方法
刚开始的时候发现测试时存在除数为零的情况,因此把操作数直接改成了1至10,避免了这种情况。
后续发现运算数只能为1到9,修改后还是无法正常测试
在老师的指点下,发现生成表达式并不应该产生等号,去掉等号后就能够正常测试了。
对结对的小伙伴做出评价(重点指出需要改进的地方)
我和我的结对伙伴是室友,整个结对过程都是坐在一起,面对面的进行讨论与修改,互相指出对方的错误,提出新的思路与想法,修改了许多bug,合作的非常愉快,感觉效率也很高,非常满意。
问题就是我的结对伙伴的IDEA过期了,因此进行了重装,修复等一系列的操作,不过我们后续还是追赶了进度,并没有耽误时间。
打分的话我会对我的小伙伴打出52分,我是48分。因为我们都是在一块进行编程,所做的工作量基本一致,她产生了代码最初轮廓,我们一块再进行修复,但是由于测试软件只能在windows系统下使用,因此最后的测试是在我的电脑上完成的,但是我们的工作量都是大致一样的,合作的也很愉快,所以我认为这个分数是合理的。
如有参考或引用的设计、实现,请进行说明
参考:http://www.cnblogs.com/vertextao/p/6896953.html
PSP
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 30 | 30 |
· Estimate | · 估计这个任务需要多少时间 | 610 | 920 |
Development | 开发 | 50 | 40 |
· Analysis | · 需求分析 (包括学习新技术) | 30 | 20 |
· Design Spec | · 生成设计文档 | 30 | 50 |
· Design Review | · 设计复审 (和同事审核设计文档) | 60 | 100 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 10 | 10 |
· Design | · 具体设计 | 100 | 90 |
· Coding | · 具体编码 | 100 | 300 |
· Code Review | · 代码复审 | 30 | 60 |
· Test | · 测试(自我测试,修改代码,提交修改) | 30 | 90 |
Reporting | 报告 | 60 | 60 |
· Test Report | · 测试报告 | 30 | 30 |
· Size Measurement | · 计算工作量 | 20 | 20 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 30 | 20 |
合计 | 610 | 920 |