20175212童皓桢 实验三敏捷开发与XP实践实验报告
发布时间:2020-12-13 22:34:21 所属栏目:Windows 来源:网络整理
导读:20175212童皓桢 实验三敏捷开发与XP实践实验报告 实验内容 XP基础 XP核心实践 相关工具 实验步骤 一、Code菜单功能的研究 Move Line/statement Down/Up:将某行、表达式向下、向上移动一行 suround with:用 try-catch,for,if等包裹语句 comment with line
20175212童皓桢 实验三敏捷开发与XP实践实验报告实验内容
二、下载搭档的Complex代码并添加单元测试1.添加搭档仓库 2.产品代码 /** * @author Jason Tong * @date 2019/4/29 14:32. */ public class Complex { // 定义属性并生成getter,setter double RealPart; double ImagePart; // 定义构造函数 public Complex(){} public Complex(double R,double I){ ImagePart = I; RealPart = R; } 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 str = ""; if (ImagePart > 0) str = RealPart + "+" + ImagePart + "i"; if (ImagePart == 0) str = RealPart + ""; if (ImagePart < 0) str = RealPart + " " + ImagePart + "i"; return str; } // 定义公有方法:加减乘除 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); } Complex ComplexDiv(Complex a) { if(a.RealPart==0||a.ImagePart==0) { System.out.println("被减数不能为0"); return new Complex(); } double d = Math.sqrt(a.RealPart*a.RealPart)+Math.sqrt(a.ImagePart*a.ImagePart); return new Complex((RealPart*a.RealPart+ImagePart*a.ImagePart)/d,Math.round((RealPart*a.ImagePart-ImagePart*a.RealPart)/d)); } } 3.测试代码 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(4.3,4.4),complex.ComplexAdd(new Complex(3.3,3.4))); } //测试加法 @Test public void testSub(){ assertEquals(new Complex(-4.3,-3.4),complex.ComplexSub(new Complex(5.3,4.4))); } //测试减法 @Test public void testMulti(){ assertEquals(new Complex(4.0,3.0),complex.ComplexMulti(new Complex(4.0,3.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),0.0))); //assertEquals(new Complex(0.0,complex.ComplexDiv(new Complex(3,4))); //边缘测试 } @Test public void testequals(){ assertEquals(true,complex.equals(new Complex(1.0,1.0))); } //测试判断相等 } 三、重构的练习原代码为: class A { final double PI=3.1415926;// PI是常量 public double getArea(final double r) { return PI*r*r; } public final void speak() { System.out.println("您好,How's everything here ?"); } } public class Example5_9 { public static void main(String args[]) { A a=new A(); System.out.println("面积:"+a.getArea(100)); a.speak(); } } 对类名以及变量名进行重构 进行封装 重构后的代码为: /** * @author Jason Tong * @date 2019/4/29 16:53. */ class Calculate { final double PI=3.1415926;// PI是常量 private int r; public double getArea() { return PI* getR() * getR(); } public final void speak() { System.out.println("您好,How's everything here ?"); } public int getR() { return r; } public void setR(int r) { this.r = r; } } public class Example5_9 { public static void main(String args[]) { Calculate a=new Calculate(); a.setR(10); System.out.println("面积:"+a.getArea()); a.speak(); } } 四、用Java完成密码学内容用java实现凯撒密码 /** * @author Jason Tong * @date 2019/5/3 16:58. */ public class Caesar { public static void main(String args[]) throws Exception{ String s=args[0]; int key=Integer.parseInt(args[1]); Movement m=new Movement(); int n=s.length(); String es=""; for(int i=0;i<s.length();i++){ char c=s.charAt(i); if(c >= 'a' && c <= 'z'){ es=m.realizeMove(n,c,key,'a','z'); } else if (c >= 'A' && c <= 'Z'){ es=m.realizeMove(n,'A','Z'); } } System.out.println(es); } } /** * @author Jason Tong * @date 2019/5/3 16:59. */ public class Movement { String es=""; public String realizeMove(int n,char c,int key,char a,char b){ //移动key%26位 c+=key%26; if(c<a) { c+=26; //向左超界 } if(c>b) { c-=26; //向右超界 } es+=c; return es; } } 实验中遇到的问题
完成代码规范
参考博客https://blog.csdn.net/weixin_42254058/article/details/81219931 http://www.cnblogs.com/rocedu/p/4795776.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在Windows 7的Git Bash中,运行黄瓜或rspec时,颜色显示为代码
- windows – 大写文件名的第一个字母
- 如何在Windows 8中增加进程的CPU利用率
- wix – 升级MSI中包含的内容
- 异常 – Windows:避免在堆栈上推送完整的x86上下文
- windows – “(.hg not found)”从cygwin托管的存储库通过s
- winapi – 什么是fadvise / madvise等效于Windows?
- Windows域用户设置用户登录脚本
- 批处理文件 – Windows批处理:无法从被调用的子例程退出 –
- windows-server-2008 – 终端服务器无法在会话中运行程序
推荐文章
站长推荐
热点阅读