1)体验敏捷开发中的两人合作。
2)进一步提高个人编程技巧与实践。
1)根据以下问题描述,练习结对编程(pair programming)实践;
2)要求学生两人一组,自由组合。每组使用一台计算机,二人共同编码,完成实验要求。
3)要求在结对编程工作期间,两人的角色至少切换 4 次;
4)编程语言不限,版本不限。建议使用 Python 或 JAVA 进行编程。
|
准备 |
选择 |
说明 |
|
平台 |
QQ屏幕分享+远程桌面控制 |
(1) 原打算使用repl.it,可能运算不当等原因,我写的代码队友看不到,且队友无法看到我的运行结果,故采取屏幕分享。 (2) 队友电脑维修中,紧急找来的电脑太卡,无法运行太多软件,故采用远程桌面控制 |
|
软件 |
Eclipse(JDK) |
基于学习Java web时安装的软件,共有,方便。 |
|
录制 |
Mirillis Action |
|
|
其他 |
两台电脑 |
|
(1)不允许任何没有经过赋值的变量存在。
(2)大括号的开始在代码块开始的行尾,闭合在和代码块同一缩进的行首。
(3)每个函数前用/**/注释,注释需包含该函数作用(function)、出现的错误(error)、以及队员双方的对函数的贡献(写write)(指导guide)。在函数内用//对重点进行注释。
(4)减少代码的循环嵌套层次,最多不超过3层。

|
Function |
Write |
Guide |
Explain |
cooperation |
|
random() |
马乐 |
丁涛 |
该函数主要负责产生运算数1、运算数2,以及运算符标识数(0-3分别代表+-*/) |
马乐负责编写代码。 丁涛负责查找Random()函数相应的知识 |
|
create() |
丁涛 |
马乐 |
主要作用为调用random()创建一个四则运算,并返回一个答案 |
丁涛负责编写代码,决定采用switch-case结构 马乐查询IO输出方式。 马乐查询资料,丁涛修改函数传参错误。 |
|
main() |
马乐 |
丁涛 |
调用create()函数,学生输入答案并与机器答案对比,给出正确数、给出分数。 |
马乐负责编写代码、查询IO输入方式 丁涛阐述逻辑结构 |
|
Solving problems |
丁涛 |
马乐 |
解决过程中函数调用问题(static与非static问题) |
马乐查询资料,丁涛负责修改Cannot make a static reference to the non-static method create() from the type main的错误 |
①随机数
import java.util.Random;
//随机产生[0,1) Math.random(); //产生[0,100) Math.random()*100; //产生[0,100)整数 (int)Math.random()*100
//产生0-3 Random rand = new Random(); int n = rand.nextInt(3);
②规则处理
|
规则 |
解决 |
|
和与积不能超过100 |
(1)对运算数1、运算数2进行限制在0-100以内 (2)对乘法和加法限制结果为<=100 |
|
差不为负 |
(1) 运算数1>=运算数2 (2) 运算数1-运算数2>=0 |
|
商不为小数或分数 |
(1) 运算数1%运算数2==0 (2) 运算数2!=0 |

|
步骤 |
运算指令 |
说明 |
|
1 |
git init |
初始化 |
|
2 |
git add . |
将所有文件添加 |
|
3 |
git commit -a |
将所有文件提交 |
|
4 |
git romote add origin XX |
连接GitHub仓库 |
|
5 |
git pull origin master |
提交分支数据 |
|
地址:https://github.com/DTer1999/Pair-Programming-about-Four-Arithmetic-Operation
|
||
1、本次实验过程中发现对Java知识掌握及其不足,例如在IO、函数调用等方面,在实验过程中犯了许多错误,如函数传参问题、函数调用静态和非静态问题,甚至将C语言的指针用到了Java上,这是极其不应该的。
2、在结对编程过程中,双方的思想极其同步,遇到不会的积极去搜查资料,队友产生疑问,及时停下,阐述自己的考虑。充分认识到结对编程的好处、优势,它可以使双方优劣互补,减少失误,加快产品开发速度,产生1+1>2的结果。
import java.util.Random;
import java.util.Scanner;
public class Pair_programming {
public int a;
public int b;
public int n;
/*
* function:产生3个随机数,分别对应运算数1、运算数2、运算符
* error:random函数如何生成随机数
* write:MaLe
* guide:DingTao
* */
public void random() {
Random rand = new Random();
a = (int)(Math.random()*100);
b = (int)(Math.random()*100);
n = rand.nextInt(3); //0-3,0代表+,1代表-,2代表*,3代表/
}
/*
* function:创建一个四则运算
* error:函数调用,无法传递参数,random(int ,int ,int)为形参,无法传递三个值
* solve:创建全局变量
* write:DingTao
* guide:MaLe
* */
public int create() {
int answer;
random();
switch(n) {
case 0:
while(a+b>100) {random();}
answer=a+b;
System.out.println(a+"+"+b+"="+"?"); //50+20=?
break;
case 1:
while(a-b<0) {random();}
answer=a-b;
System.out.println(a+"-"+b+"="+"?"); //50-20=?
break;
case 2:
while(a*b>100) {random();}
answer=a*b;
System.out.println(a+"*"+b+"="+"?");
break;
case 3:
while(b==0 || a%b!=0) {random();}
answer=a/b;
System.out.println(a+"/"+b+"="+"?"); //40/20=?
break;
default:
answer=-1;
}
return answer;
}
/*
* function:机器创建10道题目,用户输入答案,判定对错,给出正确数及分数。
* question:Cannot make a static reference to the non-static method create() from the type main
* solve:创建一个Pair_programming类的对象pair,重新调用该对象中的create()函数。
* write:MaLe
* guide:DingTao
*
* Solving problem:
* write:DingTao
* guide:Male
* */
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int answersys,answerpeo,count=0,score=0; //count正确的题目数
Pair_programming pair = new Pair_programming();
for(int i=0;i<10;i++) {
answersys=pair.create();
answerpeo=in.nextInt();
if(answerpeo==answersys) {
System.out.println("true");
count++;
score+=10;
}
else {
System.out.println("false");
}
}
System.out.println("你做对了"+count+"题目,你的得分为"+score);
}
}
原文:https://www.cnblogs.com/DTer1999/p/12630061.html