實驗三《敏捷開發與XP實踐》_實驗報告

實驗三《敏捷開發與XP實踐》_實驗報告

1、實驗內容和步驟

提交點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截圖

提交點3:

  • 任務要求
實驗三 敏捷開發與XP實踐 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的內容替換成IDEA
完成重構內容的練習,下載搭檔的代碼,至少進行三項重構,提交重構後代碼的截圖,加上本身的學號水印。提交搭檔的碼雲項目連接。
  • 實驗步驟
    • 添加做者和日期;修改方法名;添加@override標誌
  • 結果截圖

提交點4:

  • 任務要求
參考 http://www.cnblogs.com/rocedu/p/6683948.html,以結對的方式完成Java密碼學相關內容的學習,結合重構,git,代碼標準。
提交學習成果碼雲連接和表明性成果截圖,要有學號水印。
  • MD5代碼以下
    • 僞代碼
    生成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);
}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

相關文章
相關標籤/搜索