
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 |
等价类的划分
|
原文:http://www.cnblogs.com/WangLiangHui/p/5406200.html