实验三《敏捷开发与XP实践》_实验报告
一、实验内容和步骤
提交点1:
实验三 敏捷开发与XP实践 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));
}
}
- 实验步骤:
- 在IDEA的
setting
中找到plugins
并搜索alibaba
,点击install进行安装 - 重启后,在代码中右击点击编码规约扫描
- 在
code
中选择Reformate Code
格式化代码
- 实验结果
- 扫描后显示
if和for
没有大括号 - 修改后代码
提交点2:
在码云上把自己的学习搭档加入自己的项目中,确认搭档的项目加入自己后,下载搭档实验二的Complex代码,加入不少于三个JUnit单元测试用例,测试成功后git add .; git commit -m "自己学号 添加内容";git push;
提交搭档项目git log的截图,包含上面git commit的信息,并加上自己的学号水印信息。
- 实验步骤
- 下载搭档Complex代码
- 进行测试类
testAd、testSub、testMulti、testDiv
- 将测试代码传到搭档的码云
git log
- 实验结果
public class Complex{
private double r;
private double i;
public Complex(double r, double i) {
this.r = r;
this.i = i;
}
public static double getRealPart(double r) {
return r;
}
public static double getImagePart(double i) {
return i;
}
public Complex complexAdd(Complex c) {
return new Complex(r + c.r, i + c.i);
}
public Complex complexSub(Complex c) {
return new Complex(r - c.r, i - c.i);
}
public Complex complexMulti(Complex c) {
return new Complex(r * c.r - i * c.i, r * c.i + i * c.r);
}
public Complex complexDiv(Complex c) {
return new Complex((r * c.i + i * c.r)/(c.i * c.i + c.r * c.r), (i * c.i + r * c.r)/(c.i * c.i + c.r * c.r));
}
@Override
public String toString() {
String s = " ";
if (i > 0) {
s = r + "+" + i + "i";
}
if (i == 0) {
s = r + "";
}
if (i < 0) {
s = r + " " + i + "i";
}
return s;
}
}
- 测试类
import junit.framework.TestCase;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class ComplexTest extends TestCase {
Complex c1 = new Complex(0, 3);
Complex c2 = new Complex(-1, -1);
Complex c3 = new Complex(2,1);
@Test
public void testgetRealPart() throws Exception {
assertEquals(-1.0, Complex.getRealPart(-1.0));
assertEquals(5.0, Complex.getRealPart(5.0));
assertEquals(0.0, Complex.getRealPart(0.0));
}
@Test
public void testgetImagePart() throws Exception {
assertEquals(-1.0, Complex.getImagePart(-1.0));
assertEquals(5.0, Complex.getImagePart(5.0));
assertEquals(0.0, Complex.getImagePart(0.0));
}
@Test
public void testComplexAdd() throws Exception {
assertEquals("-1.0+2.0i", c1.complexAdd(c2).toString());
assertEquals("2.0+4.0i", c1.complexAdd(c3).toString());
assertEquals("1.0", c2.complexAdd(c3).toString());
}
@Test
public void testComplexSub() throws Exception {
assertEquals("1.0+4.0i", c1.complexSub(c2).toString());
assertEquals("-2.0+2.0i", c1.complexSub(c3).toString());
assertEquals("-3.0 -2.0i", c2.complexSub(c3).toString());
}
@Test
public void testComplexMulti() throws Exception {
assertEquals("3.0 -3.0i", c1.complexMulti(c2).toString());
assertEquals("-3.0+6.0i", c1.complexMulti(c3).toString());
assertEquals("-1.0 -3.0i", c2.complexMulti(c3).toString());
}
@Test
public void testComplexComplexDiv() throws Exception {
assertEquals("-1.5 -1.5i", c1.complexDiv(c2).toString());
assertEquals("1.2+0.6i", c1.complexDiv(c3).toString());
assertEquals("-0.6 -0.6i", c2.complexDiv(c3).toString());
}
}
- git log截图
![](https://img2018.cnblogs.com/blog/1592234/201905/1592234-20190505173311212-1920247789.jpg)
提交点3:
实验三 敏捷开发与XP实践 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替换成IDEA
完成重构内容的练习,下载搭档的代码,至少进行三项重构,提交重构后代码的截图,加上自己的学号水印。提交搭档的码云项目链接。
- 实验步骤
- 添加作者和日期;修改方法名;添加@override标志
- 结果截图
提交点4:
参考 http://www.cnblogs.com/rocedu/p/6683948.html,以结对的方式完成Java密码学相关内容的学习,结合重构,git,代码标准。
提交学习成果码云链接和代表性成果截图,要有学号水印。
生成MessageDigest对象:MessageDigest m=MessageDigest.getInstance("MD5");
传入需要计算的字符串:m.update(x.getBytes("UTF8" ));
计算消息摘要:byte s[ ]=m.digest( );
处理计算结果(必要的话可以使用如下代码将计算结果s转换为字符串)
- 产品代码
package 实验三;
import java.io.UnsupportedEncodingException;
import java.security.*;
public class MD5{
public static void main(String args[]) throws Exception {
String originalStr = args[0];
MessageDigest m = null;
try {
m = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
try {
m.update(originalStr.getBytes("UTF8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte byteStr[] = m.digest();
GetResult getResult = new GetResult();
for (int i = 0; i < byteStr.length; i++) {
getResult.result += Integer.toHexString((0x000000ff & byteStr[i]) |
0xffffff00).substring(6);
}
System.out.println(getResult.result);
}
public static class GetResult {
String result = "";
}
}
- 运行截图
代码托管
(链接)[https://gitee.com/wpyzka/20175226/tree/master/src/实验三]