極限編程(Extreme Programming,XP)是一種全新而快捷的軟件開發方法。XP團隊使用現場客戶、特殊計劃方法和持續測試來提供快速的反饋和全面的交流:html
XP特別適合於小型的有責任心的、自覺自勵的團隊開發需求不肯定或者迅速變化的軟件
XP軟件開發的基石是XP的活動,包括:編碼、測試、傾聽、設計。java
public class CodeStandard { public static void main(String [] args){ StringBuffer buffer = new StringBuffer(); buffer.append('S'); buf![](https://img2018.cnblogs.com/blog/1272669/201905/1272669-20190502160118003-975536005.png) fer.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)); } }
編程標準使代碼更容易閱讀和理解。編程標準包含:具備說明性的名字、清晰的表達式、直截了當的控制流、可讀的代碼和註釋,以及在追求這些內容時一致地使用某些規則和慣用法的重要性。git
Settings ->Plugins -> Browse repositories...
——安裝alibaba編碼規約掃描
不規範的地方,有中文提示而且定位到了行,alibaba把問題分爲block/critical/major三個等級。根據報錯提示,進行了修改。算法
Code->Reformate Code
從新格式化以後
編程
Code->Surround with...
功能很好用,例如咱們想改變本身代碼的部分邏輯結構,加個if語句,直接用這個功能就行了,先選擇範圍Surround後
app
提交搭檔項目git log的截圖,包含上面git commit的信息,並加上本身的學號水印信息。ide
public class Complex { double RealPart; double ImagePart; public Complex(){} public Complex(double R,double I){ RealPart=R; ImagePart=I; } public boolean equals(Complex a){ if(a.RealPart==this.RealPart&&a.ImagePart==this.ImagePart){ return true; } else { return false; } } public String toString(){ return "Complex{"+RealPart+","+ImagePart+"}"; } }
Complex: public class Complex { double RealPart; double ImagePart; public Complex(){} public Complex(double R,double I){ RealPart=R; ImagePart=I; } public boolean equals(Complex a){ if(a.RealPart==this.RealPart&&a.ImagePart==this.ImagePart){ return true; } else { return false; } } public String toString(){ return "Complex{"+RealPart+","+ImagePart+"}"; } Complex ComplexAdd(Complex a) { return new Complex(this.RealPart + a.RealPart,this.ImagePart + a.ImagePart); } Complex ComplexSub(Complex a){ return new Complex(this.RealPart - a.RealPart,this.ImagePart - a.ImagePart); } Complex ComplexMulti(Complex a){ return new Complex(this.RealPart*a.RealPart-this.ImagePart*a.ImagePart, this.ImagePart*a.RealPart+this.RealPart*a.ImagePart); } Complex ComplexDiv(Complex a){ double change = a.RealPart*a.RealPart + a.ImagePart*a.ImagePart; Complex b = new Complex(a.RealPart / change, - a.ImagePart / change); return this.ComplexMulti(b); } } ComplexTest: public class Complex { double RealPart; double ImagePart; public Complex(){} public Complex(double R,double I){ RealPart=R; ImagePart=I; } public boolean equals(Complex a){ if(a.RealPart==this.RealPart&&a.ImagePart==this.ImagePart){ return true; } else { return false; } } public String toString(){ return "Complex{"+RealPart+","+ImagePart+"}"; } Complex ComplexAdd(Complex a) { return new Complex(this.RealPart + a.RealPart,this.ImagePart + a.ImagePart); } Complex ComplexSub(Complex a){ return new Complex(this.RealPart - a.RealPart,this.ImagePart - a.ImagePart); } Complex ComplexMulti(Complex a){ return new Complex(this.RealPart*a.RealPart-this.ImagePart*a.ImagePart, this.ImagePart*a.RealPart+this.RealPart*a.ImagePart); } Complex ComplexDiv(Complex a){ double change = a.RealPart*a.RealPart + a.ImagePart*a.ImagePart; Complex b = new Complex(a.RealPart / change, - a.ImagePart / change); return this.ComplexMulti(b); } }
git push
git log
完成重構內容的練習,下載搭檔的代碼,至少進行三項重構,提交重構後代碼的截圖,加上本身的學號水印。提交搭檔的碼雲項目連接。工具
refactor->Rename
給類、包、方法、變量更名字refactor->Encapsulate Field
封裝Source->Generate toString()toString()
方法refactor->Extract Method
提煉出重複的代碼單元測試
class xmnew { private int num; private String name; private int java; public int getNum() { return num; } @Override public String toString() { return "xmnew{" + "num=" + num + ", name='" + name + '\'' + ", java=" + java + '}'; } public void setNum(int num) { this.num = num; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getJava() { return java; } public void setJava(int java) { this.java = java; } } public class xmnewTest { public static void main(String[] args) { studentdark student = new studentdark(); student.setName("caoge"); student.setNum(5312); student.setJava(94); System.out.println("學號爲"+ student.getNum() +",姓名爲"+ student.getName() +"java成績爲"+ student.getJava()); } }
提交學習成果碼雲連接和表明性成果截圖,要有學號水印。學習
KeyGenerator kg=KeyGenerator.getInstance("DESede");
FileOutputStream f=new FileOutputStream("key1.dat"); ObjectOutputStream b=new ObjectOutputStream(f); b.writeObject(k);
FileInputStream f=new FileInputStream("key1.dat"); ObjectInputStream b=new ObjectInputStream(f); Key k=(Key)b.readObject( );
Cipher cp=Cipher.getInstance("DESede");
cp.init(Cipher.ENCRYPT_MODE, k);
該方法包括兩個參數,第一個參數指定密碼器準備進行加密仍是解密,若傳入Cipher.ENCRYPT_MODE則進入加密模式。第二個參數則傳入加密或解密所使用的密鑰,即第1步從文件中讀取的密鑰對象k。String s="Hello World!"; byte ptext[]=s.getBytes("UTF8");
byte ctext[]=cp.doFinal(ptext);
FileOutputStream f2=new FileOutputStream("SEnc.dat"); f2.write(ctext);
https://gitee.com/SANFENs/Teamwork