码迷,mamicode.com
首页 > 其他好文 > 详细

20145321 实验二实验报告

时间:2016-04-17 22:26:36      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

20145321 实验二实验报告

实验内容

1.初步掌握单元测试和TDD

2.理解并掌握面向对象三要素:封装、继承、多态

3.初步掌握UML建模

4.熟悉S.O.L.I.D原则

5.了解设计模式

PSP统计

 

步骤耗时百分比
需求分析 30min 15%
设计 60min 30%
代码实现 60min 30%
测试 30min 15%
分析总结 20min 10%

实验步骤

1.使用TDD的方式设计关实现复数类Complex

(1)伪代码:

 复数类Complex
 复数=实部+虚部i
 复数相加=(实部+实部)+(虚部+虚部)i
 复数相减=(实部-实部)+(虚部-虚部)i
 打印复数
 虚部>0,“实部”+“+”+“虚部”i
 虚部<0,“实部”+“-”+“虚部”i
 虚部=0,“实部”

(2)产品代码:

 class ComplexNumber {
 private double m_dRealPart,m_dImaginPart;

 public ComplexNumber(){
    m_dRealPart = 0;
    m_dImaginPart = 0;
 }
 public ComplexNumber(double r,double I){
    m_dRealPart = r;
    m_dImaginPart = i;
 }
 public  double GetRealPart(){
    return m_dRealPart;
 }
 public double GetImaginaryPart(){
    return m_dImaginPart;
 }
 public void SetRealPart(double d){
    m_dRealPart = d;
 }
 public void SetImaginaryPart(double d){
    m_dImaginPart = d;
 }
 public ComplexNumber ComplexAdd(ComplexNumber c){
    ComplexNumber result = new ComplexNumber();
    result.SetRealPart(this.m_dRealPart+c.GetRealPart());
    result.SetImaginaryPart(this.m_dImaginPart+c.GetImaginaryPart());
    return result;
 }
 public ComplexNumber ComplexAdd(double c){
    ComplexNumber result = new ComplexNumber();
    result.SetRealPart(this.m_dRealPart+c);
    result.SetImaginaryPart(this.m_dImaginPart);
    return result;
 }
 public ComplexNumber ComplexMinus(ComplexNumber c){
    ComplexNumber result = new ComplexNumber();
    result.SetRealPart(this.m_dRealPart-c.GetRealPart());
    result.SetImaginaryPart(this.m_dImaginPart-c.GetImaginaryPart());
    return result;
 }
 public ComplexNumber ComplexMinus(double c){
    ComplexNumber result = new ComplexNumber();
    result.SetRealPart(this.m_dRealPart-c);
    result.SetImaginaryPart(this.m_dImaginPart);
    return result;
 }
 public ComplexNumber ComplexMuti(ComplexNumber c){
    ComplexNumber result = new ComplexNumber();
    result.SetRealPart(this.m_dRealPart*c.GetRealPart()-this.m_dImaginPart*c.GetImaginaryPart());
    result.SetImaginaryPart(this.m_dRealPart*c.GetImaginaryPart()+this.m_dImaginPart*c.GetRealPart());
    return result;
 }
 public ComplexNumber ComplexMuti(double c){
    ComplexNumber result = new ComplexNumber();
    result.SetRealPart(this.m_dRealPart*c);
    result.SetImaginaryPart(this.m_dImaginPart*c);
    return result;
 }
 public String toString(){
    return ""+this.m_dRealPart+"+"+this.m_dImaginPart+"i";
 }
 }

(3)测试代码:

 import org.junit.Test;  
 @Test
 public void TestStringWay() {
    ComplexNumber complexnumber = new ComplexNumber(7,3);
    System.out.println(complexnumber.toString());
    assertFquals(73.0+3.0i",complexnumber.toString());
 }

2.单元测试

技术分享

技术分享

技术分享

3.StarUML建模

技术分享

20145321 实验二实验报告

标签:

原文地址:http://www.cnblogs.com/5321z/p/5402280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!