《我的结对项目心得》

 

点滴成就

学习时间

新编写代码行数

博客量(篇)

学到知识点

 

 

 

 

 

第一周

8h

0

0

组成团队,角色分配

第二周

8h

0

1

确定团队项目

第三周

12h

0

1

使用博客,制作调查问卷,环境图

第四周

14h

105

1

软件需求文档,用例图,需求分析结对编程,代码规范

 第五周

 12h

 0

 0

 类图

第六周

10h

200

0

顺序图,状态图

 第七周

14h

 0

 1

 软件系统设计文档,软件测试

 
结对对象:王良辉2013110436
 
双方贡献比例:  1:1
 
结对照片
 
 
题目
  某公司程序员二柱的小孩上了小学二年级,老师让家长每天出30道(100以内)四则运算题目给小学生做。二柱立马就想到写一个小程序来做这件事。 这个事情可以用很多语言或者工具来实现:
•Excel、C/C++、Java、C#、VB、Unix Shell、Vbscript、Javascript、Perl、 Python、…
 
源程序

/**
 *
 */
package wpy.test;

import java.util.Scanner;
import java.util.Scanner;

public class main {
 
    public static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args) {
     
        int i=30;
        int correct=0;
       
        Output out;
       
        while(i>0){
         
        out=new Output();
       
        System.out.print(out.getString());
        String s=scanner.nextLine();
       
        if(out.panduan(s)){
            System.out.println("回答正确!");
            correct++;
        }else{
            System.err.println("回答错误!");
        }
        i--;
        System.out.println("还有"+i+"道题未回答");
        }
       
        System.out.println("恭喜你!,回答完毕,回答正确的为"+correct+"道");

    }
}

output.java

package wpy.test;

import java.util.Random;

public class Output {

    private int a, b;
    private int i;
    private String operator[]={"+","-","×","÷"};

    public Output(){

      while(true){

        a=new Random().nextInt(100);
        b=new Random().nextInt(100);
        i=new Random().nextInt(4);

        if(i==1&&a<b){      
            continue;
        }

        if(i==3){            
            if(b==0){
                continue;
            }
            if(a%b!=0){     
                continue;
            }
        }
        break;     
      }
    }

    public String getString(){
       return new String(a+operator[i]+b+"=");
    }

    public  boolean panduan(String s){
        int i,result = 0;
        try{
            i=Integer.valueOf(s).intValue();
        }catch(Exception e){
            return false;
        }

        switch(this.operator().toCharArray()[0]){
           case '+':result=this.getA()+this.getB();break;
           case '-':result=this.getA()-this.getB();break;
           case '×':result=this.getA()*this.getB();break;
           case '÷':result=this.getA()/this.getB();break;
        }

        if(result==i){
            return true;
        }return false;
    }

    public String operator(){
        return operator[this.i];
    }
   
    public int getA() {
        return a;
    }

    public int getB() {
        return b;
    }
}

  

测试结果
 
总结
优点:
  1.通过结对编程,可以提高写代码的速度。
  2.写出的代码Bug相对于一个来说更少。
  3.队友之间可以相互学习,共同提高。
  4.可以交替写代码,减少工作量。
缺点:
  1.两个人想法不同的时候容易产生争执。
  2.写代码习惯不一样,容易产生有的地方看不懂的情况。
总之,“结对编程”优点还是多于缺点,我们还是可以多通过这种练习来提高我们的编程能力。
原文地址:https://www.cnblogs.com/wpy0032/p/5375308.html