實驗三 敏捷開發與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