实验三 敏捷开发与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)); } }
setting
中找到plugins
并搜索alibaba
,点击install进行安装code
中选择Reformate Code
格式化代码if和for
没有大括号在码云上把本身的学习搭档加入本身的项目中,确认搭档的项目加入本身后,下载搭档实验二的Complex代码,加入很多于三个JUnit单元测试用例,测试成功后git add .; git commit -m "本身学号 添加内容";git push; 提交搭档项目git log的截图,包含上面git commit的信息,并加上本身的学号水印信息。
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()); } }
实验三 敏捷开发与XP实践 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替换成IDEA 完成重构内容的练习,下载搭档的代码,至少进行三项重构,提交重构后代码的截图,加上本身的学号水印。提交搭档的码云项目连接。
参考 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转换为字符串)
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);
}html
public static class GetResult { String result = ""; }
}
```java
- 运行截图
(连接)[https://gitee.com/wpyzka/20175226/tree/master/src/%E5%AE%9E%E9%AA%8C%E4%B8%89]git