Experiment 3 Agile Development and XP Practice

20165225 Experiment 3 Agile Development and XP Practice Experiment Report


Experiment report cover:

课程:Java程序设计  班级:1652班  姓名:王高源 学号:20165225

指导教师:娄嘉鹏 实验日期:2018年4月128日

实验时间:3:35 - 5:15 实验序号:实验三

实验名称:敏捷开发与XP实践

实验内容:
1.XP基础
2.XP核心实践
3.相关工具

实验要求:

- 没有Linux基础的同学建议先学习《Linux基础入门(新版)》《Vim编辑器》 课程

- 完成实验、撰写实验报告,实验报告以博客方式发表在博客园,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等)、解决办法(空洞的方法如“查网络”、“问同学”、“看书”等一律得0分)以及分析(从中可以得到什么启示,有什么收获,教训等)。报告可以参考范飞龙老师的指导
严禁抄袭,有该行为者实验成绩归零,并附加其他惩罚措施。

Experimental steps:

(1) Coding standard
  • Programming standards make code easier to read and understand, and even guarantee fewer bugs in it. Programming standards include: declarative names, clear expressions, straightforward control flow, readable code and comments, and the importance of using certain rules and idioms consistently when pursuing these.

  • Regarding the indentation of the program, it is more intelligent in IDEA, it will automatically indent for you, which also greatly enhances the readability of the program.

  • General naming rules in Java:

1. To reflect their respective meanings

2. Packages, classes, variables with nouns

3. The method name uses the verb object

4. The package name is all lowercase, such as: io, awt

5. The first letter should be capitalized, such as: HelloWorldApp

6. The first letter of the variable name should be lowercase, such as: userName

7. The first letter of the method name should be lowercase: setName

8. In team operations, the format specification is to clear the way to improve efficiency; naming conventions

9. Fan is very flexible, and it is carried out according to the different situations and habits of each team, which is not only convenient for myself, but also for other members of the team.

  • Pair programming:

  • Two important roles in pair programming: the driver is the person who controls the keyboard input, and the navigator plays the role of navigating and reminding.
    Driver: Write design documentation, do coding and unit testing and other XP development processes. Navigator: Review the driver's documentation, the driver's execution of development processes such as coding; consider the coverage of unit tests; think about whether and how to refactor; help the driver to solve specific technical problems.
    The pilot and navigator constantly rotate roles, do not work more than an hour continuously, and take a 15-minute break for every hour of work. The navigator has to control the time.

  • Our common code is as follows:

    public class CodeStandard {
    public static void main(String [] args){
    StringBuffer buffer = new StringBuffer();
    buffer.append('S');
    buffer.append("tringBuffer");
    System.out.println(buffer.charAt(1));
    System.out.println(buffer.capacity());
    System.out.println(buffer.indexOf("tring"));
    System.out.println("buffer = " + buffer.toString());
    if(buffer.capacity()<20)
    buffer.append("1234567");
    for(int i=0; i<buffer.length();i++)
    System.out.println(buffer.charAt(i));
    }
    }
  • But such code is not indented and it is very laborious to read, so we should use Code->Reformate Code in idea to format the code.

  • After the code is reformatted, the effect is as follows:

    public class CodeStandard {
        public static void main(String [] args){
            StringBuffer buffer = new       StringBuffer();
            buffer.append('S');
            buffer.append("tringBuffer");
            System.out.println(buffer.charAt(1));
            System.out.println(buffer.capacity());
            System.out.println(buffer.indexOf("tring"));
            System.out.println("buffer = " + buffer.toString());
            if(buffer.capacity()<20)
                buffer.append("1234567");
            for(int i=0; i<buffer.length();i++)
                System.out.println(buffer.charAt(i));
        }
    }

image

  • In fact, idea also has many very useful functions, such as: Surround With(Ctrl+Alt+T): You can use if-else, try-catch, do-while, etc. to wrap code segments, which greatly simplifies our programming time:

image

(2) Agile development and XP

  • Add your learning partner to your own project on the code cloud. After confirming that the partner's project is added to yourself, download the Complex code of partner experiment 2, add no less than three JUnit unit test cases, and git add .; git after the test is successful commit -m "Add content to your student number"; git push;

  • Complete the refactoring exercises, download your partner's code, perform at least three refactorings, submit a screenshot of the refactored code, and add your own student ID watermark. Submit your partner's code cloud project link.

  • Complete the learning of Java cryptography related content in pairs, combined with refactoring, git, and code standards. Submit the learning outcome code cloud link and representative results screenshots, with a student ID watermark.

-Partner code:

import java.lang.Integer;
import java.util.Objects;

public class Complex {
    //定义属性并生成getter,setter
    double RealPart;
    double ImagePart;
    public double getRealPart(){
        return RealPart;
    }
    public double getImagePart(){
        return ImagePart;
    }

    //定义构造函数
    public Complex(){
        RealPart = 0;
        ImagePart = 1;
    }
    public Complex(double R,double I){
        RealPart = R;
        ImagePart = I;
    }

    //Override Object
    public boolean equals(Object obj){
        if(this == obj){
            return true;
        }
        if(!(obj instanceof Complex)) {
            return false;
        }
        Complex complex = (Complex) obj;
        if(complex.RealPart != ((Complex) obj).RealPart) {
            return false;
        }
        if(complex.ImagePart != ((Complex) obj).ImagePart) {
            return false;
        }
        return true;
    }
    public String toString(){
        String s = new String();
        if (ImagePart > 0){
            s = getRealPart() + "+" + getImagePart() + "i";
        }
        if (ImagePart == 0){
            s = getRealPart() + "";
        }
        if(ImagePart < 0){
            s = getRealPart() + "" + getImagePart() + "i";
        }
        if(RealPart == 0){
            s = getImagePart() + "i";
        }
        return s;
    }
    //定义公有方法:加减乘除
    Complex ComplexAdd(Complex a){
        return new Complex(RealPart + a.RealPart,ImagePart + a.ImagePart);
    }
    Complex ComplexSub(Complex a){
        return new Complex(RealPart - a.RealPart,ImagePart - a.ImagePart);
    }
    Complex ComplexMulti(Complex a){
        return new Complex(RealPart*a.RealPart-ImagePart*a.ImagePart,RealPart*a.ImagePart + ImagePart*a.RealPart);
    }
    Complex ComplexDiv(Complex a) {
        return new Complex((RealPart * a.ImagePart + ImagePart * a.RealPart) / (a.ImagePart * a.ImagePart + a.RealPart * a.RealPart), (ImagePart * a.ImagePart + RealPart * a.RealPart) / (a.RealPart * a.RealPart + a.RealPart * a.RealPart));
    }
}
  • Test code:

    import static org.junit.Assert.*;
    import org.junit.Test;
    import junit.framework.TestCase;
    public class ComplexTest extends TestCase {
    Complex complex = new Complex(1,1);
    @Test
    public void testAdd(){
        assertEquals(new Complex(3.3,3.4), complex.ComplexAdd(new Complex(2.3,2.4)));
    }
    //测试加法
    @Test
    public void testSub(){
        assertEquals(new Complex(-5.3,-2.4), complex.ComplexSub(new Complex(6.3,3.4)));
    }
    //测试减法
    @Test
    public void testMulti(){
        assertEquals(new Complex(3.0,2.0), complex.ComplexMulti(new Complex(3.0,2.0)));
    }
    //测试乘法
    @Test
    public void testDiv(){
        assertEquals(new Complex(1.0,1.0), complex.ComplexDiv(new Complex(1.0,1.0)));
        assertEquals(new Complex(0.0,0.0), complex.ComplexDiv(new Complex(1.0,0.0)));
        //assertEquals(new Complex(0.0,0.0), complex.ComplexDiv(new Complex(3,4)));
        //边缘测试
    }
    @Test
    public void testequals(){
        assertEquals(true, complex.equals(new Complex(1.0,1.0)));
    }
    //测试判断相等
    }
  • The test results are as follows:

image

  • Partner to join the code cloud project:

image

  • git command upload code:

    $ cd /home/shiyanlou/Code/shiyanlou_cs212
    # 修改代码文件
    # 添加修改文件
    $ git add 所有修改的文件
    # 提交到环境中本地代码仓库
    $ git commit -m '本次修改的描述'
    # push到git.shiyanlou.com,无需输入密码
    $ git push
  • Code cloud upload screenshot:

image

(3) Refactoring

  • Refactoring is to change the internal structure of the software to make it easier to read, maintain and change without changing the external behavior of the software. The main goal of refactoring is to clear the "smelly" code, which is mainly manifested as repetitive code.

  • Let's still take the partner's complex as an example:

- Select the refactoring project as shown:

image

The reconstruction result is as follows:

image

(4) Practice

Experience:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325077652&siteId=291194637