zoukankan      html  css  js  c++  java
  • 结对编程2

    1.结对照片

    2.结对说明

    结对对象:蔡何   博客地址:http://www.cnblogs.com/compilers/

    双方贡献:1:2

    3.题目

    构造程序,分别是:
    •不能触发Fault。
    •触发Fault,但是不能触发Error。
    •触发Error,但是不能产生Failure。
    4.程序描述
    输入两个整数A B ,range in [-100 , 100],若A B都小于 0,则输出 All less than 0;否则就判断A B中的最大值y = max(A,B), y是否处于[25 ,65] 之间,若处于,则输出 25 <= max(A,B) <=65,否则输出 Illegal !
     
     
    4.源代码
    package pair_program_2;
    
    import java.util.Scanner;
    
    /**
     * 
     * @author JackCai
     * @brief 输入两个整数A B ,range in [-100 ,- 100],若A B都小于 0,则输出 All less than 0
     *        ;否则就判断A B中的最大值y = max(A,B), y是否处于[25 ,65] 之间,若处于,则输出 25 <= max(A,B) <=
     *        65,否则输出 Illegal !
     *
     */
    public class PairProgram2 {
        public static int opA;
        /** <opA number */
        public static int opB;
        /** <opB number */
        public static int maxValue;
        /** <maxValue */
    
        private final static int ZERO = 0;
        private final static int LEG_RANGE_LOW = 25;
        private final static int LEG_RANGE_HIGHT = 65;
        private final static int RANGE_LOW = -100;
        private final static int RANGE_HIGHT = 100;
    
        private static Scanner scanner = new Scanner(System.in);
    
        /**
         * @brief this is the main function of this program
         * @param [in] args
         */
        public static void main(String args[]) {
            opA = getUserInput(); // 获取操作数A
            opB = getUserInput(); // 获取操作数B
    
            if (opA < ZERO && opB < ZERO) {
                System.out.println("All less than 0 !");
                return;
            }
            // otherwise
            maxValue = max(opA, opB); // 获取两者的MAX值
            if (maxValue >= LEG_RANGE_LOW && maxValue <= LEG_RANGE_HIGHT) { // 满足在
                                                                            // [25,65]之间的话,则输出
                System.out.println(LEG_RANGE_LOW + " <= max(" + opA + " , " + opB
                        + ") <= " + LEG_RANGE_HIGHT);
            } else {
                System.out.println("Illegal !"); // 否则就输出 Illegal !
            }
        }
    
        /**
         * @brief this function to get the max value between A and B (PS: some fault
         *        in these code)
         * @param [in] opA
         * @param [in] opB
         * @return
         */
        public static int max(int opA, int opB) {
            int temp = opA;
            if (opB > opA) {
                temp = opA;
            }
            return temp;
        }
    
        /**
         * @brief this function to get input data from user
         * @return int
         */
        public static int getUserInput() {
            int value = -1;
            System.out
                    .println("please enter a integer number,range in [-100,100]:");
            while (true) {
                if (scanner.hasNextInt()) {
                    value = scanner.nextInt();
                    if (value >= RANGE_LOW && value <= RANGE_HIGHT) {
                        break;
                    } else {
                        System.out
                                .println("Illegal range, should be in [-100,100],try again: ");
                    }
                } else {
                    scanner.nextLine(); // flush cache
                    System.out.println("please enter right number:");
                }
            }
            return value;
        }
    }

     6.测试

      •不能触发Fault。
      
      •触发Fault,但是不能触发Error。
      •触发Error,但是不能产生Failure。
  • 相关阅读:
    [NOIP2017 TG D2T2]宝藏(模拟退火)
    [洛谷P1337][JSOI2004]平衡点 / 吊打XXX
    [洛谷P4940]Portal2
    [CF1073E]Segment Sum
    [CF1066C]Books Queries
    [CF1065C]Make It Equal
    [洛谷P3469][POI2008]BLO-Blockade
    网络模型 ------->MobileNet-v3
    C++--------------------->>>>>>cmakelist的编写
    C++ ----------------》》》》》cmake list的
  • 原文地址:https://www.cnblogs.com/ccgy/p/5401092.html
Copyright © 2011-2022 走看看