本次作业要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2213
一、从个人项目出发,将程序改造成一个单机带用户界面(不是控制台)的程序,这个程序最基本要达到:
二、下面附有 8 个相互独立的可以扩展的方向。
附:八个可扩展方向:
三、同学两两结对,每对学生选取 8 个可扩展方向的其中4个加以实现。
(这里我们选择了实现2,4,6,8四个方向。)
开发环境:IntelliJ IDEA 2018.2
GitHub上面提交了这个项目的JAR可运行文件
四、估计实现所需时间,记录结对编程时间,并写在博客中。
PSP2.1 | Personal Software Process Stages | Time Senior Student(h) | Time(h) |
Planning | 计划 | 24 | 36 |
· Estimate | 估计这个任务需要多少时间 | 10 | 12 |
Development | 开发 | 10 | 12 |
· Analysis | 需求分析 (包括学习新技术) | 1 | 2 |
· Design Spec | 生成设计文档 | 1 | 1 |
· Design Review | 设计复审 | 1 | 1 |
· Coding Standard | 代码规范 | 1 | 1 |
· Design | 具体设计 | 1 | 2 |
· Coding | 具体编码 | 1 | 2 |
· Code Review | 代码复审 | 1 | 1 |
· Test | 测试(自我测试,修改代码,提交修改) | 1 | 1 |
Reporting | 报告 | 1 | 1 |
· | 测试报告 | 1 | 1 |
· | 计算工作量 | 1 |
1 |
· | 并提出过程改进计划 | 1 |
1 |
五,主要代码
阶乘运算
else if (e.getSource() == Btn_Factorial) { L_test.setText("题目:"); T_inputText.setText(""); L_info_pr.setText(""); T_answerText.setText(""); number = (int) (Math.random() * 10); L_test_pr.setText(number + "!"); if (number == 0) { result = 1; } else { for (int i = 1; i <= number; i++) { result = result * i; } } } }
提交答案与下一题的按钮事件
/** * 提交答案 */ else if (e.getSource() == Btn_submit) { String str_answer = T_answerText.getText(); answer = Integer.parseInt(str_answer); if (answer == result) { L_info_pr.setText("回答正确!"); right++; } else { L_info_pr.setText("回答错误!正确答案为:" + result); wrong++; } } /** * 下一题 */ else if (e.getSource() == Btn_next) { if (n > 1) { n--; L_info_pr.setText(""); T_answerText.setText(""); test(); L_test.setText("题目" + j + ":"); j++; } else { L_info_pr.setText("题目已做完!正确题数:" + right + ";错误题数:" + wrong); } }
换肤功能
else if (e.getSource() == Btn_change) { switch (backColor) { case 0: this.getContentPane().setBackground(Color.red); break; case 1: this.getContentPane().setBackground(Color.lightGray); break; case 2: this.getContentPane().setBackground(Color.GREEN); break; case 3: this.getContentPane().setBackground(Color.yellow); break; case 4: this.getContentPane().setBackground(Color.blue); break; case 5: this.getContentPane().setBackground(Color.magenta); break; case 7: this.getContentPane().setBackground(Color.white); break; } backColor++; backColor = backColor % 7; }
主要算法
public void test() { Random rand = new Random(); num1 = rand.nextInt() % 99 + 1; num2 = rand.nextInt() % 99 + 1; num3 = rand.nextInt() % 99 + 1; op1 = (int) (Math.random() * 4 + 1); op2 = (int) (Math.random() * 4 + 1); String str_num1 = String.valueOf(num1); String str_num2 = String.valueOf(num2); String str_num3 = String.valueOf(num3); if (num1 < 0) { str_num1 = String.valueOf("(" + num1 + ")"); } if (num2 < 0) { str_num2 = String.valueOf("(" + num2 + ")"); } if (num3 < 0) { str_num3 = String.valueOf("(" + num3 + ")"); }
六,运行截图
主界面
主要运行效果
统计结果
换肤功能
阶乘运算功能
七,总结
结对伙伴:201606120016梁林森 负责主要算法与答案的判断 他的博客地址:http://www.cnblogs.com/LinsenLiang/
我主要实现窗体还有换肤以及阶乘的算法 我的github地址: https://github.com/GzccCzc/Czc
总结这次结对编程的收获到和感悟:结对子编程有助于项目的快速进展,简单点描述就是遇到问题了,可以通过两个人之间的快速沟通与问题一致性的默契去解决问题,避免了单人完成项目遇到难题时不知所措的惨境。通过这次编程也算是重新学习了以前的JAVA SWING知识,算是温故而知新吧。而且这次的作业是在上次的基础完成的,所以有了更清晰的思路。学无止境,比我们厉害的人太多了,需要不断的学习学习再学习。
还有今天是1024程序员日,希望各位程序员(还有代码的搬运工)都能开开心心吧哈哈哈。
原文:https://www.cnblogs.com/StuCzc/p/9827520.html