结对编程 第二阶段

一、实验目标
  1)体验敏捷开发中的两人合作。

  2)进一步提高个人编程技巧与实践。

二 、实验内容
  1)根据以下问题描述,练习结对编程(pair programming)实践;

  2)要求学生两人一组,自由组合。每组使用一台计算机,二人共同编码,完成实验要求。

  3)要求在结对编程工作期间,两人的角色至少切换 4 次;

  4)编程语言不限,版本不限。建议使用 Python 或 JAVA 进行编程。

1、代码规范

1.1 类名首字母应该大写,字段、方法以及对象的首字母应小写。对于所有标识符,其中包含的所有单词都应该紧靠在一起,而且中间单词的首字母大写。

Cell.java  Map.java  updateStatus

1.2 尽可能地加上注释。

1.3 注意缩进,换行,对齐。

2、程序的总体设计

3程序结对编程过程(附图)及功能实现情况(附代码和图)

Cell.java

package methods;
public class Cell {
  private int Status; //dead '0' or living '1'
  private int LivingNum; //the number of living neighbor cells

  public Cell(int stau) {
  // TODO create a cell with a ramdom status
   this.Status = stau;
  }

  public int getCellStatus() {
  // TODO get this cell status
    return this.Status;
  }

  public void setCellStatus(int stau) {
  //TODO this stau are only two values '0' or '1'
    this.Status = stau;
  }

  public int getLivingNum() {
  //TODO
    return this.LivingNum;
  }

  public void setLivingNum(int living) {
    this.LivingNum = living;
  }

  public void setNextStatus() {
  //TODO judge the next round status of cells
    if(this.getLivingNum() == 3) {
     this.setCellStatus(1);
    }
    else if(this.getLivingNum()<2 || this.getLivingNum()>3){
    //other numbers will lead to death
    this.setCellStatus(0);
    }
    else {
    //remain the status
    this.setCellStatus(this.Status);
    }
  }
}

4、项目Github地址

https://github.com/wbr1224/LifeGame

5、实验总结

在本次实验的过程中切身体会到了结对编程确实提高了代码的质量,大大降低了出错率。

多双眼睛,少点bug。

缺点是分散注意力。

原文地址:https://www.cnblogs.com/Rising-zmm/p/12583174.html