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

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

作者:互联网

一、实验内容

二、实验步骤

package Experiment;

public class ComplexWZH {
    double realPart;
    double imagePart;
    public ComplexWZH() {}
    public ComplexWZH(double r, double i) {
        realPart = r;
        imagePart = i;
    }
    public double getRealPart() {
        return realPart;
    }
    public double getImagePart() {
        return imagePart;
    }
    @Override
    public boolean equals(Object obj) {
        if(this == obj) {
            return true;
        }
        if(obj == null) {
            return false;
        }
        if(getClass() != obj.getClass()) {
            return false;
        }
        if(!(obj instanceof ComplexWZH)) {
            return false;
        } else {
            ComplexWZH complexWZH = (ComplexWZH) obj;
            if (complexWZH.imagePart == ((ComplexWZH) obj).imagePart) {
                return true;
            }
            if (complexWZH.realPart == ((ComplexWZH) obj).realPart) {
                return true;
            }
        }
        return false;
    }
    @Override
    public  String toString() {
        String str = "";
        if (realPart == 0&& imagePart == 0) {
            str = "0.0";
        } else if (realPart == 0&& imagePart != 0) {
            str = imagePart + "" + "i";
        } else if (realPart != 0&& imagePart == 0) {
            str = realPart + "";
        } else if (realPart !=0&& imagePart > 0) {
            str = realPart + "" + "+" + imagePart + "i";
        } else if (realPart !=0&& imagePart < 0) {
            str = realPart + "" + imagePart + "i";
        }
        return str;
    }
    public ComplexWZH complexAdd(ComplexWZH a) {
        return new ComplexWZH(realPart + a.getRealPart(), imagePart + a.getImagePart());
    }
    public ComplexWZH complexSub(ComplexWZH a) {
        return new ComplexWZH(realPart - a.getRealPart(), imagePart - a.getImagePart());
    }
    public ComplexWZH complexMulti(ComplexWZH a) {
        return new ComplexWZH(realPart *a.getRealPart() - imagePart *a.getImagePart(), realPart *a.getImagePart() + imagePart *a.getRealPart());
    }
    public ComplexWZH complexDiv(ComplexWZH a) {
        if(a.getRealPart() == 0&&a.getImagePart() == 0) {
            System.out.println("除数不能为0");
            return new ComplexWZH();
        }
        else {
            return new ComplexWZH((realPart *a.getRealPart() - imagePart *a.getImagePart())/(a.getRealPart()*a.getRealPart()-a.getImagePart()*a.getImagePart()),(realPart *a.getImagePart() + imagePart *a.getRealPart())/(a.getRealPart()*a.getRealPart()-a.getImagePart()*a.getImagePart()));
        }
    }
}
package Experiment;

import junit.framework.TestCase;
import org.junit.Test;
public class ComplexWZHTest extends TestCase {
 ComplexWZH a = new ComplexWZH(2.0,5.0);
 ComplexWZH b = new ComplexWZH(1.0,-4.0);
 ComplexWZH c = new ComplexWZH(-3.0,2.0);
 ComplexWZH d = new ComplexWZH(-4.0,-3.0);
 ComplexWZH e = new ComplexWZH(0.0,0.0);
 @Test
 public void testgetRealPart() throws Exception {
     assertEquals(2.0,a.getRealPart());
     assertEquals(1.0,b.getRealPart());
     assertEquals(-3.0,c.getRealPart());
     assertEquals(-4.0,d.getRealPart());
     assertEquals(0.0,e.getRealPart());
 }
 @Test
 public void testgetImagePart() throws Exception {
     assertEquals(5.0,a.getImagePart());
     assertEquals(-4.0,b.getImagePart());
     assertEquals(2.0,c.getImagePart());
     assertEquals(-3.0,d.getImagePart());
     assertEquals(0.0,e.getImagePart());
 }
 @Test
 public void testequals() throws Exception {
     assertEquals(true,a.toString().equals(a.toString()));
     assertEquals(false,b.toString().equals(c.toString()));
     assertEquals(false,d.toString().equals(e.toString()));
 }
 @Test
 public void testtoString() throws Exception {
     assertEquals("2.0+5.0i",a.toString());
     assertEquals("1.0-4.0i",b.toString());
     assertEquals("-3.0+2.0i",c.toString());
     assertEquals("-4.0-3.0i",d.toString());
     assertEquals("0.0",e.toString());
 }
 @Test
 public void testComplexAdd() throws Exception {
     assertEquals("3.0+1.0i",a.ComplexAdd(b).toString());
     assertEquals("-7.0-1.0i",c.ComplexAdd(d).toString());
     assertEquals("-4.0-3.0i",d.ComplexAdd(e).toString());
 }
 @Test
 public void testComplexSub() throws Exception {
     assertEquals("1.0+9.0i",a.ComplexSub(b).toString());
     assertEquals("1.0+5.0i",c.ComplexSub(d).toString());
     assertEquals("-3.0+2.0i",c.ComplexSub(e).toString());
 }
 public void testComplexMulti() throws Exception {
     assertEquals("22.0-3.0i",a.ComplexMulti(b).toString());
     assertEquals("18.0+1.0i",c.ComplexMulti(d).toString());
     assertEquals("0.0",b.ComplexMulti(e).toString());
 }
 public void testComplexDiv() throws Exception {
     assertEquals("-1.4666666666666666+0.2i",a.ComplexDiv(b).toString());
     assertEquals("2.5714285714285716+0.14285714285714285i",c.ComplexDiv(d).toString());
     assertEquals("0.0",a.ComplexDiv(e).toString());
 }
}

/**
 * ComplexWZH
 * @author 林郅聪
 * @date 2019/5/1
 */
package Experiment;

@SuppressWarnings({"ALL", "AlibabaLowerCamelCaseVariableNaming"})
public class ComplexWZH {
    @SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
    double realPart;
    double imagePart;
    public ComplexWZH() {}
    public ComplexWZH(double r, double i) {
        realPart = r;
        imagePart = i;
    }
    public double getRealPart() {
        return realPart;
    }
    public double getImagePart() {
        return imagePart;
    }
    @Override
    public boolean equals(Object obj) {
        if(this == obj) {
            return true;
        }
        if(obj == null) {
            return false;
        }
        if(getClass() != obj.getClass()) {
            return false;
        }
        if(!(obj instanceof ComplexWZH)) {
            return false;
        } else {
            ComplexWZH complexWZH = (ComplexWZH) obj;
            if (complexWZH.imagePart == ((ComplexWZH) obj).imagePart) {
                return true;
            }
            if (complexWZH.realPart == ((ComplexWZH) obj).realPart) {
                return true;
            }
        }
        return false;
    }
    @Override
    public  String toString() {
        String str = "";
        if (realPart == 0&& imagePart == 0) {
            str = "0.0";
        } else if (realPart == 0&& imagePart != 0) {
            str = imagePart + "" + "i";
        } else if (realPart != 0&& imagePart == 0) {
            str = realPart + "";
        } else if (realPart !=0&& imagePart > 0) {
            str = realPart + "" + "+" + imagePart + "i";
        } else if (realPart !=0&& imagePart < 0) {
            str = realPart + "" + imagePart + "i";
        }
        return str;
    }
    public ComplexWZH complexAdd(ComplexWZH a) {
        return new ComplexWZH(realPart + a.getRealPart(), imagePart + a.getImagePart());
    }
    public ComplexWZH complexSub(ComplexWZH a) {
        return new ComplexWZH(realPart - a.getRealPart(), imagePart - a.getImagePart());
    }
    public ComplexWZH complexMulti(ComplexWZH a) {
        return new ComplexWZH(realPart *a.getRealPart() - imagePart *a.getImagePart(), realPart *a.getImagePart() + imagePart *a.getRealPart());
    }
    public ComplexWZH complexDiv(ComplexWZH a) {
        if(a.getRealPart() == 0&&a.getImagePart() == 0) {
            System.out.println("除数不能为0");
            return new ComplexWZH();
        }
        else {
            return new ComplexWZH((realPart *a.getRealPart() - imagePart *a.getImagePart())/(a.getRealPart()*a.getRealPart()-a.getImagePart()*a.getImagePart()),(realPart *a.getImagePart() + imagePart *a.getRealPart())/(a.getRealPart()*a.getRealPart()-a.getImagePart()*a.getImagePart()));
        }
    }
}

-4.Java密码学相关内容

三、实验中遇到的问题

四、伙伴评价

伙搭档学习热情很高,一直督促我学习,过程中也帮助我很多,是很好的学习伙伴。

五、码云链接

我的码云链接:链接
伙伴的码云链接:链接

标签:return,assertEquals,imagePart,ComplexWZH,2019,2018,20175214,realPart,public
来源: https://www.cnblogs.com/fzlzc/p/10812869.html