结对编程(二)
?
?
結對對象:吳鵬宇2013110438 博客地址:http://www.cnblogs.com/wpy0032/ 雙方貢獻比例: ?1:1 結對照片 題目: 構造程序,分別是: ?不能觸發Fault。 ?觸發Fault,但是不能觸發Error。 ?觸發Error,但是不能產生Failure。 源程序 提示用戶輸入兩個值,兩個值必須在0~100,若不滿足條件則提示錯誤,若兩個值都小于10,則輸出輸入都小于10,程序退出。否則根據輸入的值判斷使用加法還是減法,若輸入的第一個數小于第二個數,則使用減法計算,否則就使用加法。 1 package wpy.test;2 3 import java.util.Scanner;4 5 public class test {6 private static Scanner in = new Scanner(System.in);7 private static final int RANGE_LOW = 0;// 允許用戶輸入的最小值8 private static final int RANGE_HIGH = 100;// 允許用戶輸入的最大值9 private static final int LIMIT = 10; 10 private static int result;// 返回結果 11 12 13 public static int getUserInput() { 14 int number = -1; 15 System.out.println("請輸出0~100的整數!"); 16 while (true) { 17 if (in.hasNextInt()) { 18 number = in.nextInt(); 19 if (number > RANGE_HIGH || number < RANGE_LOW) { 20 System.err.println("輸入不在1~100!"); 21 } else { 22 break; 23 } 24 } else { 25 in.nextLine(); 26 System.out.println("請輸入整數!"); 27 } 28 } 29 return number; 30 } 31 32 33 public static int getResult(int num1, int num2) { 34 if (num1 < num2) { 35 return num1 + num2; 36 } 37 return num1 + num2; 38 } 39 40 public static void main(String[] args) { 41 int op1 = getUserInput(); 42 int op2 = getUserInput(); 43 System.out.println("******************************************************"); 44 System.out.println("第一次輸入 " + op1 + " 第二次輸入 " + op2); 45 if (op1 < LIMIT && op2 < LIMIT) { 46 System.out.println("輸入都小于 10!!!"); 47 return; 48 } 49 result = getResult(op1, op2); 50 if (result > 0) { 51 if (result > 100) { 52 System.out.println("Illegal!"); 53 } else { 54 System.out.println("和為 " + result); 55 } 56 } else { 57 if (result < -50) { 58 System.out.println("Illegal!"); 59 } else { 60 System.out.println("差為 " + result); 61 } 62 } 63 } 64 65 }測試結果
?不能觸發Fault。
? ?觸發Fault,但是不能觸發Error。
? ?觸發Error,但是不能產生Failure。
總結
?通過這次結對編程,對軟件中fault,error,failure 有了進一步的認識和理解.受益匪淺。
| 點滴成就 | 學習時間 | 新編寫代碼行數 | 博客量(篇) | 學到知識點 |
| ? | ? | ? | ? | ? |
| 第一周 | 8h | 0 | 0 | 組成團隊,角色分配 |
| 第二周 | 8h | 0 | 1 | 確定團隊項目 |
| 第三周 | 12h | 0 | 1 | 使用博客,制作調查問卷,環境圖 |
| 第四周 | 14h | 105 | 1 | 軟件需求文檔,用例圖,需求分析結對編程,代碼規范 |
| ?第五周 | ?12h | ?0 | ?0 | ?類圖 |
| 第六周 | 10h | 200 | 0 | 順序圖,狀態圖 |
| ?第七周 | 14h | ?0 | ?1 | ?軟件系統設計文檔,軟件測試 |
| 第八周 | 10h | 65 | 1 | 等價類的劃分 ? |
轉載于:https://www.cnblogs.com/WangLiangHui/p/5406200.html
總結
- 上一篇: 第三章--数据类型
- 下一篇: Swift快速入门(一)第一个Swift