结对编程--保龄球实验

1.实验目的通过结对编程完成保龄球计分程序

2.实验过程:

(1):首先我们两个一起商讨编写保龄球积分程序需要什么方法,经过十几分钟的商讨我们一致决定一共需要

public static int flag[] =new int[10];//判断状态: 0: 2次没中10;, 1 :补中 ;2:第一次全中
public static int[] finScore =new int[10];//每轮分数
public static int[][] eachScore = new int[10][3];
public static void getScore(int firstSore,int secondSore,int count ){}
这几个方法到主方法中

(2):当确定好大致思路时我们就开始了编写代码,当我和我的搭档刚开始结对编程的时候还有些不习惯,

但是两个人结对编程确实容易发现错误,当我在主方法外写判断方法public  int flag[] =new int[10];,引用到

主方法时一直报错,而我也迟迟没找到错误,我的搭档发现我居然忘记写了static,怪不得主方法一直引用不

了,经过搭档的指正我也是改正了过来正确的应该是public static int flag[] =new int[10];

(3):我跌跌撞撞写了将近半个小时,程序总是有各种问题,于是我把电脑推个了我的搭档,然后由我来观察

,当他在写得分方法

public static void getScore(int firstSore,int secondSore,int count ){
if(firstSore!=10){
eachScore[count][0] = firstSore;
if(10-firstSore>secondSore){
flag[count]=0;
eachScore[count][1]=secondSore;
finScore[count] =firstSore+secondSore;
System.out.println("本轮为"+(count+1)+"轮,2次都没全中"+"本轮成绩为"+finScore[count]);
}else if(10-firstSore==secondSore){
flag[count]=1;
eachScore[count][1]=secondSore;
finScore[count]=10;
 System.out.println("本轮为"+(count+1)+"轮,补中。"+"本轮成绩暂时为"+finScore[count]+",等下一轮补分");}        }

这时我看出了不对劲我的搭档好像少写了一个条件,现在只有补种和两次都没不中的情况,一次就全中的情况他忘记

写了,经过我的提醒他把这个条件又写上了,现在的代码是这样的

public static void getScore(int firstSore,int secondSore,int count ){
if(firstSore!=10){
eachScore[count][0] = firstSore;
if(10-firstSore>secondSore){
flag[count]=0;
eachScore[count][1]=secondSore;
finScore[count] =firstSore+secondSore;
System.out.println("本轮为"+(count+1)+"轮,2次都没全中哦~"+"本轮成绩为"+finScore[count]);
}else if(10-firstSore==secondSore){
flag[count]=1;
eachScore[count][1]=secondSore;
finScore[count]=10;
System.out.println("本轮为"+(count+1)+"轮,补中。"+"本轮成绩暂时为"+finScore[count]+",等下一轮补分");
}
}else{
flag[count]=2;
eachScore[count][0]=10;
eachScore[count][1]=0;
finScore[count]=10;
System.out.println("本轮为"+(count+1)+"全中。"+"本轮成绩暂时为"+finScore[count]+",等下一轮补分");};

3.实验收获:经过这次结对编程让我学会了保龄球的积分规则,而且也让我和我的搭档了解到了结对编程的益处,
结对编程容易发现自己一个人不容易发现的错误,大大的提高了编写代码的速度和准确性。
 
posted @ 2023-03-19 20:47  派大星的亲大舅子  阅读(34)  评论(0编辑  收藏  举报