其他分享
首页 > 其他分享> > 2018-2019-2 20175216实验三《敏捷开发与XP实践》实验报告

2018-2019-2 20175216实验三《敏捷开发与XP实践》实验报告

作者:互联网

2018-2019-2 20175216实验三《敏捷开发与XP实践》实验报告

实验三 敏捷开发与XP实践

实验步骤

1、 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替换成IDEA
参考 http://www.cnblogs.com/rocedu/p/6371315.html#SECCODESTANDARD 安装alibaba 插件,解决代码中的规范问题。
在IDEA中使用工具(Code->Reformate Code)把下面代码重新格式化,再研究一下Code菜单,找出一项让自己感觉最好用的功能。提交截图,加上自己学号水印。
实验代码:

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));
}
}
/**
 * Demo class
 *
 * @author 20175216
 * @date 2019/04/29
 */
import junit.framework.TestCase;
import org.junit.Test;
public class StringBufferDemoTest extends TestCase {
    StringBuffer buffer = new StringBuffer("StringBuffer");
    @Test
    public void testcharAt(){
        assertEquals('S',buffer.charAt(0));
    }
    @Test
    public void testcapacity(){
        assertEquals(28,buffer.capacity());
    }
    @Test
    public void testindexof(){
        assertEquals(1,buffer.indexOf("tring"));
    }
    @Test
    public void testtoString(){
        assertEquals("StringBuffer",buffer.toString());
    }
}
名称 快捷键 功能
Override Methods Ctrl + O 重写覆盖方法
Implements Methods Ctrl + I 实现接口方法
Gengrate Alt + Insert 生成Construct、Getter/Setter、toString等
Surround With Ctrl + Alt +T 生成包围代码
Unwarp/Remove Ctrl + Shift + Delete 取消代码包围
Cyclic Expand Word Alt + / 循环往上选择单词
Cyclic Expand Word Backwrad 循环往下选择单词
Comment with Line Comment Ctrl + / 行注释
Comment with Block Comment Ctrl + Shift + / 块注释
Reformat Code Ctrl + Alt + L 格式化代码
Move Statement Down Ctrl + Shift + ↓ 方法、代码下移
Move Statement Up Ctrl + Shift + ↑ 方法、代码上移

图片4_水印.png

2、在码云上把自己的学习搭档加入自己的项目中,确认搭档的项目加入自己后,下载搭档实验二的Complex代码,加入不少于三个JUnit单元测试用例,测试成功后git add .; git commit -m "自己学号 添加内容";git push;
提交搭档项目git log的截图,包含上面git commit的信息,并加上自己的学号水印信息。

public class Complex {
    public double getRealPart() {
        return RealPart;
    }

    public double getImagePart() {
        return ImagePart;
    }

    double RealPart;
    double ImagePart;

    public void setRealPart(double realPart) {
        RealPart = realPart;
    }

    public void setImagePart(double imagePart) {
        ImagePart = imagePart;
    }

    public Complex(){}
    public Complex(double R,double I){
        this.ImagePart = I;
        this.RealPart = R;
    }


    @Override
    public String toString() {
        return "Complex{" +
                "RealPart=" + RealPart +
                ", ImagePart=" + ImagePart +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Complex complex = (Complex) o;
        return Double.compare(complex.getRealPart(), getRealPart()) == 0 &&
                Double.compare(complex.getImagePart(), getImagePart()) == 0;
    }

    Complex ComplexAdd(Complex a) {
        return new Complex(this.RealPart + a.RealPart,this.ImagePart + a.ImagePart);
    }
    Complex ComplexSub(Complex a){
        return new Complex(this.RealPart - a.RealPart,this.ImagePart - a.ImagePart);
    }
    Complex ComplexMulti(Complex a){
        return new Complex(this.RealPart*a.RealPart-this.ImagePart*a.ImagePart,
                this.ImagePart*a.RealPart+this.RealPart*a.ImagePart);
    }
    Complex ComplexDiv(Complex a){
        double scale = a.getRealPart()*a.getRealPart() + a.getImagePart()*a.getImagePart();
        Complex b = new Complex(a.getRealPart() / scale, - a.getImagePart() / scale);
        return this.ComplexMulti(b);
    }
}

3、实验三 敏捷开发与XP实践 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替换成IDEA。
完成重构内容的练习,下载搭档的代码,至少进行三项重构,提交重构后代码的截图,加上自己的学号水印。提交搭档的码云项目链接。

/**
 * Demo class
 *
 * @author 20175203
 * @date 2019/04/29
 */
public class Complex {
    public double getRealPart() {
        return RealPart;
    }

    public double getImagePart() {
        return ImagePart;
    }

    double RealPart;
    double ImagePart;

    public void setRealPart(double realPart) {
        RealPart = realPart;
    }

    public void setImagePart(double imagePart) {
        ImagePart = imagePart;
    }

    public Complex(){}
    public Complex(double R,double I){
        this.ImagePart = I;
        this.RealPart = R;
    }


    @Override
    public String toString() {
        return "Complex{" +
                "RealPart=" + RealPart +
                ", ImagePart=" + ImagePart +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Complex complex = (Complex) o;
        return Double.compare(complex.getRealPart(), getRealPart()) == 0 &&
                Double.compare(complex.getImagePart(), getImagePart()) == 0;
    }

    Complex ComplexAdd(Complex a) {
        return new Complex(this.RealPart + a.RealPart,this.ImagePart + a.ImagePart);
    }
    Complex ComplexSub(Complex a){
        return new Complex(this.RealPart - a.RealPart,this.ImagePart - a.ImagePart);
    }
    Complex ComplexMulti(Complex a){
        return new Complex(this.RealPart*a.RealPart-this.ImagePart*a.ImagePart,
                this.ImagePart*a.RealPart+this.RealPart*a.ImagePart);
    }
    Complex ComplexDiv(Complex a){
        double scale = a.getRealPart()*a.getRealPart() + a.getImagePart()*a.getImagePart();
        Complex b = new Complex(a.getRealPart() / scale, - a.getImagePart() / scale);
        return this.ComplexMulti(b);
    }
}

实验三-4_水印.png
实验三--01_水印.png

实验总结

通过Java第二次实验,我学会了更多的知识,例如:代码标准,代码重构,Java中密码学算法等内容。

代码标准和重构的学习,使我注意到自己之前编写代码时的很多不规范之处,而且通过使用alibaba的实时编码扫描,使我在编写代码的同时,注意规范代码的标准格式,使写出的代码更加客观好看,容易分析,类名和变量名的规范,也使我在编写代码时,减少了许多不必要的注释。

标签:return,double,ImagePart,Complex,2019,2018,20175216,RealPart,public
来源: https://www.cnblogs.com/besti20175216/p/10802416.html