zoukankan      html  css  js  c++  java
  • 结对编程--fault,error,failure的程序设计

    一.结对编程内容:

      1.不能触发Fault。

      2.触发Fault,但是不触发Error。

      3.触发Error,但不触发Failure。

    二.结对编程人员

      1.周浩,周宗耀

      2.结对截图:

    三.结对项目编程

      1.不能触发Fault:  

     1 package com.hao_mini.www;
     2 
     3 import java.util.Scanner;
     4 
     5 public class True {
     6 
     7     public static void main(String[] args) {
     8         Scanner in=new Scanner(System.in);
     9         int i=in.nextInt();
    10         int[] TrueArray=new int[i];
    11         for(int j=0;j<TrueArray.length;j++){
    12             TrueArray[j]=in.nextInt();
    13         }
    14         for(int j=0;j<TrueArray.length;j++){
    15         System.out.println(TrueArray[j]);
    16         }
    17         in.close();
    18     }
    19 
    20 }

      2.触发Fault,但是不触发Error:

     1 package com.hao_mini.www;
     2 
     3 import java.util.Scanner;
     4 
     5 public class Nofault {
     6     public static void main(String[] args) {
     7         Scanner in=new Scanner(System.in);
     8         int i;
     9         i=in.nextInt();
    10         int counti=0;
    11         for(int j=1;j<i;j++){
    12             counti++;
    13         }
    14         System.out.println(counti);
    15         in.close();
    16     }
    17 }

     

        分析:在11行  for(int j=1;j<i;j++){  触发了Fault,但并未造成Error

      3.触发Error,但不触发Failure:

    1 package com.hao_mini.www;
     2 
     3 import java.util.Scanner;
     4 
     5 public class HaveFaultNotError {
     6 
     7     public static void main(String[] args) {
     8         Scanner in=new Scanner(System.in);
     9         
    10         System.out.println("请输入长度");
    11         int i=in.nextInt();
    12         int[] TestArray=new int[i];
    13         int sum=0,j=0;
    14         for(;j<TestArray.length-1;j++){
    15             TestArray[j]=in.nextInt();
    16             sum+=TestArray[j];
    17         }
    18         int avg=sum/j;
    19         System.out.println("avg="+avg);
    20         in.close();
    21     }
    22 
    23 }

      分析:在 14 行到17行  for(;j<TestArray.length-1;j++){ }处存在Error,并且触发了Error(sum=6 预期中间变量sum=9) , Failure((预期avg=sum(9)/3=3)

    实际avg=sum(6)/2)  未触发。

    四.分析与总结

      在这次结对中,更深入的认识到了这三者的关系,并逐渐接受了结对编程的编程思想。

  • 相关阅读:
    分享ASP.NET+jQuery MiniUI后台购物管理
    ASP.NET发送电子邮件
    LINQ学习(三):Where子句
    ASP.NET配置KindEditor文本编辑器
    一步步写自己SqlHelper类库(五):Command对象
    ASP.NET生成静态页面的简单实现
    兼职开发悟出的点点滴滴
    设计模式学习笔记
    if else替代者
    ASP.NET 一生命周期中的额事件
  • 原文地址:https://www.cnblogs.com/hao-mini/p/5409090.html
Copyright © 2011-2022 走看看