git
2)在开始实现程序以前,在下述程序员
任务内容算法 |
计划共完成须要的时间(min)编程 |
|
Planning模块化 |
计划函数 |
25性能 |
· Estimate单元测试 |
· 估计这个任务须要多少时间,并规划大体工做步骤学习 |
10天测试 |
Development |
开发 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
90 |
· Design Spec |
· 生成设计文档 |
5 |
· Design Review |
· 设计复审 (和同事审核设计文档) |
4 |
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
10 |
· Design |
· 具体设计 |
10 |
· Coding |
· 具体编码 |
600 |
· Code Review |
· 代码复审 |
35 |
· Test |
· 测试(自我测试,修改代码,提交修改) |
60 |
Reporting |
报告 |
9 |
· Test Report |
· 测试报告 |
60 |
· Size Measurement |
· 计算工做量 |
2 |
· Postmortem & Process Improvement Plan |
· 过后总结, 并提出过程改进计划 |
10 |
3)看教科书和其它资料中关于Information Hiding, Interface Design, Loose Coupling的章节,说明大家在结对编程中是如何利用这些方法对接口进行设计的。
信息隐藏(Information Hiding)
信息隐藏指在设计和肯定模块时,使得一个模块内包含的特定信息(过程或数据),对于不须要这些信息的其余模块来讲,是不可访问的。信息隐藏有着独特的启发力,它可以激发出有效的设计方案。信息隐藏一样有助于设计类的公开接口。
咱们的信息隐藏设计: 类的全部数据成员都是private,全部访问都是经过访问函数实现的;
接口设计(Interface Design)
接口能够下降耦合性,便可以让某个模块或功能可以重复利用。
咱们的设计:能够了解对象的交互界面,而不需了解对象所对应的类。
松耦合(Loose Coupling)
松耦合:即下降功能模块之间的依赖度。
咱们的设计: 采用模块化设计,将方法进行封装,每一个类之间保持独立,下降耦合度
1 if (c ==0 && b == 0) { 2 String answer = Lib2.compute1(ns, os, m1s, m2s); 3 label.setText(answer); 4 } 5 if (c != 1 && b == 1) { 6 String answer = Lib2.compute2(ns, os, m1s, m2s); 7 label.setText(answer); 8 } 9 if (c == 1 && b != 1) { 10 String answer = Lib2.compute3(ns, os, m1s, m2s); 11 label.setText(answer); 12 } 13 if (c == 1 && b == 1) { 14 String answer = Lib2.compute4(ns, os, m1s, m2s); 15 label.setText(answer); 16 }
F4回收垃圾后,发现红色所有消失,资源所有被回收。证实没有资源泄露。程序性能良好。
1 import static org.junit.Assert.*; 2
3 import org.junit.Test; 4
5 public class test { 6 Lib2 lib = new Lib2(); 7 @Test 8 public void test() { 9 lib.compute1(12, 2, 1, 100); 10 lib.compute2(12, 2, 1, 100); 11 lib.compute3(12, 2, 1, 100); 12 lib.compute4(12, 2, 1, 100); 13
14 } 15
16 }
样例1:n为非法字符(字母,符号等,这里以字母为例)。
@Test public void testn1command() { String[] args={"-n","e","-m","1","100"}; Command.main(args); }
样例2:n超出预计范围(n小于1或大于10000,这里以-9为例)。
@Test public void testn2command() { String[] args={"-n","-9","-m","1","100"}; Command.main(args); }
样例3:m1,m2超出预计范围(m1大于m2或者m1小于1大于100或者m2小于50大于1000,这里以m1为-8,m2为40为例)。
@Test public void testm1command() { String[] args={"-n","10","-m","-8","40"}; Command.main(args); }
样例4:m为非法字符(字母,符号等,这里以字母为例)。
@Test public void testm2command() { String[] args={"-n","10","-m","8","e"}; Command.main(args); }
样例5:m,n为空值
@Test public void testmncommand() { String[] args={}; Command.main(args); }
作题界面,设置监听器,当触发“下一题”的按钮事件时,根据用户定制的要求,进行出题。
1 class ButtonListener implements ActionListener { 2 public void actionPerformed(ActionEvent e) { 3 Lib2 lib2 = new Lib2(); 4 int ns = Integer.parseInt(n.getText()); 5 int os = Integer.parseInt(o.getText()); 6 int m1s = Integer.parseInt(m1.getText()); 7 int m2s = Integer.parseInt(m2.getText()); 8 if (e.getSource() == jbtBeginCompute) { 9 JFrame frame2 = new JFrame(); 10 frame2.setTitle("作题界面"); 11 frame2.setSize(500, 500); 12 frame2.setLocationRelativeTo(null); 13 frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 14 frame2.setVisible(true); 15 if (c ==0 && b == 0) { 16 String answer = Lib2.compute1(ns, os, m1s, m2s); 17 label.setText(answer); 18 } 19 if (c != 1 && b == 1) { 20 String answer = Lib2.compute2(ns, os, m1s, m2s); 21 label.setText(answer); 22 } 23 if (c == 1 && b != 1) { 24 String answer = Lib2.compute3(ns, os, m1s, m2s); 25 label.setText(answer); 26 } 27 if (c == 1 && b == 1) { 28 String answer = Lib2.compute4(ns, os, m1s, m2s); 29 label.setText(answer); 30 } 31
32 panel1.add(label); 33 JPanel panel2 = new JPanel(); 34 panel2.add(new JLabel("请输入答案:")); 35 panel2.add(text); 36 JButton buttonSubmit = new JButton("提交答案"); 37 JButton buttonNext = new JButton("下一题"); 38 JPanel panel3 = new JPanel(); 39 panel3.add(buttonNext); 40 panel3.add(buttonSubmit); 41
42 frame2.add(panel1, BorderLayout.NORTH); 43 frame2.add(panel2, BorderLayout.CENTER); 44 frame2.add(panel3, BorderLayout.SOUTH); 45 frame2.setSize(500, 500); 46 frame2.setLocationRelativeTo(null); 47 frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 48 frame2.setVisible(true); 49 }
核对答案:
1 buttonNext.addActionListener(new ActionListener() {// 定义时间监听器
2 public void actionPerformed(ActionEvent e) { 3 System.out.println("下一题"+lib2.result); 4 String question = label.getText(); 5 int count = 0; 6 double sum = Double.parseDouble(text.getText()); 7 if (count < ns) { 8 String ifRight = ""; 9 if (lib2.result == sum) { 10 ifRight = "正确"; 11 rightSum++; 12 count++; 13 } else { 14 ifRight = "错误"; 15 count++; 16 } 17 String message = question + ", " + "你的答案:" + sum + ", " + "正确答案: " + lib2.result + ", 状态: "
18 + ifRight; 19 list.add(message); 20 text.setText(""); 21 if (c ==0 && b == 0) { 22 String answer = Lib2.compute1(ns, os, m1s, m2s); 23 label.setText(answer); 24 } 25 if (c != 1 && b == 1) { 26 String answer = Lib2.compute2(ns, os, m1s, m2s); 27 label.setText(answer); 28 } 29 if (c == 1 && b != 1) { 30 String answer = Lib2.compute3(ns, os, m1s, m2s); 31 label.setText(answer); 32 } 33 if (c == 1 && b == 1) { 34 String answer = Lib2.compute4(ns, os, m1s, m2s); 35 label.setText(answer); 36 } 37 } 38 } 39 });
输入“题目数量、运算符个数、数值上下界范围、是否带乘除和括号”后,选择开始作题。
有计算作题时间的功能。
若是选择“上传题目”
将用户上传的题目逐一展现出来,用户可在此界面作题。
答题完毕后,自动审核,展现错题库。
结对编程的优势:
1)在开发层次,结对编程能提供更好的设计质量和代码质量,两人合做能有更强的解决问题的能力。
2)两个程序员之间能够相互教对方,进行优劣势的互补。
结对编程的缺点:
1)两我的在一块儿工做可能会出现工做精力不能集中的状况。程序员可能会交谈一些与工做无关的事情,反而分散注意力,致使效率比单人更为低下。
2)有时候,程序员们会对一个问题互不相让(代码风格可能会是引起技术人员口水战的地方),争吵不休,反而产生重大内耗。
搭档的优缺点:性格好,有耐心,心细,有规划。能够实现互帮互助,一块儿学习,有时候,会对一个问题很坚持,缺乏变通性。
个人优缺点:好沟通,愿意共享,喜欢一块儿学习,耐性比较差,有时不够细心。
任务内容 |
实际完成须要的时间(min) |
|
Planning |
计划 |
30 |
· Estimate |
· 估计这个任务须要多少时间,并规划大体工做步骤 |
10天 |
Development |
开发 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
45 |
· Design Spec |
· 生成设计文档 |
8 |
· Design Review |
· 设计复审 (和同事审核设计文档) |
6 |
· Coding Standard |
· 代码规范 (为目前的开发制定合适的规范) |
15 |
· Design |
· 具体设计 |
30 |
· Coding |
· 具体编码 |
500 |
· Code Review |
· 代码复审 |
80 |
· Test |
· 测试(自我测试,修改代码,提交修改) |
120 |
Reporting |
报告 |
6 |
· Test Report |
· 测试报告 |
90 |
· Size Measurement |
· 计算工做量 |
8 |
· Postmortem & Process Improvement Plan |
· 过后总结, 并提出过程改进计划 |
10 |