结对编程学习总结博文

1.确定本次实验结对编程合作伙伴;

我的小伙伴为:王志成

2.各自运行合作伙伴实验九编程练习1,结合使用体验对所运行程序提出完善建议;

3.各自运行合作伙伴实验十编程练习2,结合使用体验对所运行程序提出完善建议;

程序互测概述:

  我和小伙伴互相测试了对方的实验九编程练习1程序,小伙伴的程序基本要求都能达到,就是在文件的读取上面还有些欠缺,但是在后面的共同学习中他很好的改了过来。实验十编程练习2中基本功能要求也同样能实现,只是在除法上面有点缺陷没有很好地实现实数运算。

程序互测心得:

  通过本次和小伙伴的程序互测体验,其好处在于帮助别人发现问题的同时还可反思自己的程序,认识自己的不足。而且很有效的提升了自己阅读代码的能力。

4.采用结对编程方式,与学习伙伴合作完成实验九编程练习1;

结对编程代码

  1 package jiedui_bianchen;
  2 
  3 import java.io.BufferedReader;
  4 import java.io.File;
  5 import java.io.FileInputStream;
  6 import java.io.FileNotFoundException;
  7 import java.io.IOException;
  8 import java.io.InputStreamReader;
  9 import java.util.ArrayList;
 10 import java.util.Scanner;
 11 import java.util.Collections;
 12 
 13 public class ID {
 14 
 15     public static People findPeopleByname(String name) {
 16         People flag = null;
 17         for (People people : peoplelist) {
 18             if(people.getName().equals(name)) {
 19                 flag = people;
 20             }
 21         }
 22         return flag;
 23 
 24     }
 25 
 26     public static People findPeopleByid(String id) {
 27         People flag = null;
 28         for (People people : peoplelist) {
 29             if(people.getnumber().equals(id)) {
 30                 flag = people;
 31             }
 32         }
 33         return flag;
 34 
 35     }
 36      
 37     private static ArrayList<People> agenear(int yourage) {
 38         // TODO Auto-generated method stub
 39         int j=0,min=53,d_value=0,k = 0;
 40         ArrayList<People> plist = new ArrayList<People>();
 41         for (int i = 0; i < peoplelist.size(); i++) {
 42             d_value = peoplelist.get(i).getage() > yourage ? 
 43                     peoplelist.get(i).getage() - yourage : yourage - peoplelist.get(i).getage() ;
 44             k = d_value < min ? i : k;
 45             min = d_value < min ? d_value : min;
 46         }
 47         for(People people : peoplelist) {
 48             if(people.getage() == peoplelist.get(k).getage()) {
 49                 plist.add(people);
 50             }
 51         }
 52         return plist;
 53     }
 54 
 55     private static ArrayList<People> peoplelist; 
 56     
 57     public static void main(String[] args) //throws  IOException
 58     {
 59         peoplelist = new ArrayList<People>();
 60         Scanner scanner = new Scanner(System.in);
 61         File file = new File("D:\\身份证号.txt");
 62         try {
 63             FileInputStream files = new FileInputStream(file);
 64             BufferedReader in = new BufferedReader(new InputStreamReader(files));
 65             String temp = null;
 66             while ((temp = in.readLine()) != null) {
 67                 
 68                 String[] information = temp.split("[ ]+");
 69                 People people = new People();
 70                 people.setName(information[0]);
 71                 people.setnumber(information[1]);
 72                 int A = Integer.parseInt(information[3]);
 73                 people.setage(A);
 74                 people.setsex(information[2]);
 75                 for(int j = 4; j<information.length;j++) {
 76                     people.setplace(information[j]);
 77                 }
 78                 peoplelist.add(people);
 79 
 80             }
 81         } catch (FileNotFoundException e) {
 82             System.out.println("文件未找到");
 83             e.printStackTrace();
 84         } catch (IOException e) {
 85             System.out.println("文件读取错误");
 86             e.printStackTrace();
 87         }
 88         boolean isTrue = true;
 89         while (isTrue) {
 90 
 91             System.out.println("******************************************");
 92             System.out.println("   1.按姓名典序输出人员信息");
 93             System.out.println("   2.查询最大年龄人员信息");
 94             System.out.println("   3.查询最小年龄人员信息");
 95             System.out.println("   4.输入你的年龄,查询身份证号.txt中年龄与你最近的人");
 96             System.out.println("   5.查询人员中是否有你的同乡");
 97             System.out.println("   6.退出");
 98             System.out.println("******************************************");
 99             int nextInt = scanner.nextInt();
100             switch (nextInt) {
101             case 1:
102                 Collections.sort(peoplelist);
103                 System.out.println(peoplelist.toString());
104                 break;
105             case 2:
106                 int max=0;
107                 int j,k1 = 0;
108                 for(int i=1;i<peoplelist.size();i++)
109                 {
110                     j = peoplelist.get(i).getage();
111                    if(j>max)
112                    {
113                        max = j; 
114                        k1 = i;
115                    }
116                   
117                 }  
118                 System.out.println("年龄最大:"+peoplelist.get(k1));
119                 break;
120             case 3:
121                 int min = 100;
122                 int j1,k2 = 0;
123                 for(int i=1;i<peoplelist.size();i++)
124                 {
125                     j1 = peoplelist.get(i).getage();
126                     if(j1<min)
127                     {
128                         min = j1; 
129                         k2 = i;
130                     }
131 
132                  } 
133                 System.out.println("年龄最小:"+peoplelist.get(k2));
134                 break;
135             case 4:
136                 System.out.println("年龄:");
137                 int input_age = scanner.nextInt();
138                 ArrayList<People> plist = new ArrayList<People>();
139                 plist = agenear(input_age);
140                 for(People people : plist) {
141                     System.out.println(people.toString());
142                 }
143                 break;
144             case 5:
145                 System.out.println("请输入省份");
146                 String find = scanner.next();        
147                 for (int i = 0; i <peoplelist.size(); i++) 
148                 {
149                     String [] place = peoplelist.get(i).getplace().split("\t");
150                     for(String temp : place) {
151                         if(find.equals(temp)) {
152                             System.out.println("你的同乡是    "+peoplelist.get(i));
153                             break;
154                         }
155                     }
156                     
157                 } 
158                 break;
159             case 6:
160                 isTrue = false;
161                 System.out.println("byebye!");
162                 break;
163             default:
164                 System.out.println("输入有误");
165             }
166         }
167     }
168 
169 }

结对程序运行功能界面截图;

结对过程描述,提供两人在讨论、细化和编程时的结对照片(非摆拍)。

   本次结对编程实验,我的小伙伴充当领航员的角色,审阅代码、对编码等开发流程的执行,并考虑单元测试的覆盖程度;是否需要和如何重构;帮助我解决程序中具体的技术问题。在一些基础语法和技术问题上给了我很大的启发。我充当驾驶员的角色,主要为写设计文档,进行编码和单元测试等XP开发流程。本次实验实际操作都由我来完成,在领航员的带领下我们一步步完成了这次实验。得到了以前独自实验中没有的益处。比如,代码编写风格的不同,阅读方式的不同,对知识点理解的不同,虽然在过程中出现了争论,但最后还是有了一致的答案。

5.采用结对编程方式,与学习伙伴合作完成实验十编程练习2。

结对编程代码;

  1 import java.io.File;
  2 import java.io.FileOutputStream;
  3 import java.io.PrintWriter;
  4 import java.math.BigDecimal;
  5 import java.util.Scanner;
  6 
  7 
  8 public class ss {
  9     public static void main(String[] args) {
 10 
 11 
 12         Scanner in = new Scanner(System.in);
 13         Calculator<Integer> sf = new Calculator<Integer>();
 14         File file = new File("wzt.txt");
 15         if(file.exists()) {
 16             System.out.println("文件已存在");
 17         }
 18         PrintWriter output = null;
 19         try {
 20             output = new PrintWriter(new FileOutputStream(file));
 21         } catch (Exception e) {
 22             //e.printStackTrace();
 23         }
 24         int sum = 0;
 25         
 26         System.out.println("计算结果保留两位小数");
 27         for (int i = 1; i < 11; i++) {
 28             int a = (int) Math.round(Math.random() * 100);
 29                 int b = (int) Math.round(Math.random() * 100);
 30                 int s = (int) Math.round(Math.random() * 3);
 31 
 32             
 33            switch(s)
 34            {
 35            case 1:
 36                System.out.println(i+": "+a+"/"+b+"=");
 37                Number c = in.nextDouble();
 38                output.println(a+"/"+b+"="+c);
 39                Number g = sf.division(a, b);
 40                BigDecimal division = new BigDecimal(g.doubleValue());
 41                g = division.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
 42                if (c.equals(g)) {
 43                    sum += 10;
 44                    System.out.println("恭喜答案正确");
 45                }
 46                else {
 47                    System.out.println("抱歉,答案错误");
 48                }
 49             
 50                break;
 51             
 52            case 2:
 53                System.out.println(i+": "+a+"*"+b+"=");
 54                Number c1 = in.nextDouble();
 55                output.println(a+"*"+b+"="+c1);
 56                Number g1 = sf.mulitiplication(a, b);
 57                BigDecimal mul = new BigDecimal(g1.doubleValue());
 58                g1 = mul.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
 59                if (c1.equals(g1) ){
 60                    sum += 10;
 61                    System.out.println("恭喜答案正确");
 62                }
 63                else {
 64                    System.out.println("抱歉,答案错误");
 65                }
 66                break;
 67            case 3:
 68                System.out.println(i+": "+a+"+"+b+"=");
 69                Number c2 = in.nextDouble();
 70                output.println(a+"+"+b+"="+c2);
 71                Number g2 =sf.addition(a, b);
 72                BigDecimal add = new BigDecimal(g2.doubleValue());
 73                g2 = add.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
 74                if (c2.equals(g2)) {
 75                    sum += 10;
 76                    System.out.println("恭喜答案正确");
 77                }
 78                else {
 79                    System.out.println("抱歉,答案错误");
 80                }
 81                
 82                break ;
 83            case 4:
 84                System.out.println(i+": "+a+"-"+b+"=");
 85                Number c3 = in.nextDouble();
 86                output.println(a+"-"+b+"="+c3);
 87                Number g3 = sf.subtraction(a, b);
 88                BigDecimal sub = new BigDecimal(g3.doubleValue());
 89                g3 = sub.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
 90                if (c3.equals(g3)) {
 91                    sum += 10;
 92                    System.out.println("恭喜答案正确");
 93                }
 94                else {
 95                    System.out.println("抱歉,答案错误");
 96                }
 97                break ;
 98 
 99                } 
100     
101           }
102         System.out.println("成绩"+sum);
103         output.println("成绩:"+sum);
104         output.close();
105         in.close();
106          
107     }
108 }

结对程序运行功能界面截图;

结对过程描述,提供两人在讨论、细化和编程时的结对照片(非摆拍)。

  本次结对编程实验,我们互换了角色,由我充当领航员的角色,进行审阅代码、对编码等开发流程的执行,并考虑单元测试的覆盖程度;是否需要和如何重构;在编写代码时帮助我的小伙伴改正一些由于疏忽造成的代码的一些错误。确定代码的主题思维和风格,我的小伙伴充当驾驶员的角色,主要为写设计文档,进行编码和单元测试等XP开发流程。本次实验实际操作都由我的小伙伴来完成,在我们的的共同努力下我们一步步完成了这次实验。得到了以前独自实验中没有的益处。这次实验中,我收获了意想不到的益处,在驾驶员编程的同时因为我不用编写代码,我可以有大量时间更有效地整理我们的思维逻辑,思考更多更优的编程方式。这都是在平时自己独自编程时没有的。

猜你喜欢

转载自www.cnblogs.com/hackerZT-7/p/9941434.html