相關工具html
Insert Live Template:插入一些記不起來的 Live Template 縮寫
java
1.添加搭檔倉庫
2.產品代碼git
/** * @author Jason Tong * @date 2019/4/29 14:32. */ public class Complex { // 定義屬性並生成getter,setter double RealPart; double ImagePart; // 定義構造函數 public Complex(){} public Complex(double R,double I){ ImagePart = I; RealPart = R; } public boolean equals(Object obj){ if(this == obj) { return true; } if(!(obj instanceof Complex)) { return false; } Complex complex = (Complex) obj; if(complex.RealPart != ((Complex) obj).RealPart) { return false; } if(complex.ImagePart != ((Complex) obj).ImagePart) { return false; } return true; } public String toString() { String str = ""; if (ImagePart > 0) str = RealPart + "+" + ImagePart + "i"; if (ImagePart == 0) str = RealPart + ""; if (ImagePart < 0) str = RealPart + " " + ImagePart + "i"; return str; } // 定義公有方法:加減乘除 Complex ComplexAdd(Complex a) { return new Complex(RealPart+a.RealPart,ImagePart+a.ImagePart); } Complex ComplexSub(Complex a) { return new Complex(RealPart-a.RealPart,ImagePart-a.ImagePart); } Complex ComplexMulti(Complex a) { return new Complex(RealPart*a.RealPart,ImagePart*a.ImagePart); } Complex ComplexDiv(Complex a) { if(a.RealPart==0||a.ImagePart==0) { System.out.println("被減數不能爲0"); return new Complex(); } double d = Math.sqrt(a.RealPart*a.RealPart)+Math.sqrt(a.ImagePart*a.ImagePart); return new Complex((RealPart*a.RealPart+ImagePart*a.ImagePart)/d,Math.round((RealPart*a.ImagePart-ImagePart*a.RealPart)/d)); } }
3.測試代碼數據結構
import static org.junit.Assert.*; import org.junit.Test; import junit.framework.TestCase; public class ComplexTest extends TestCase { Complex complex = new Complex(1,1); @Test public void testAdd(){ assertEquals(new Complex(4.3,4.4), complex.ComplexAdd(new Complex(3.3,3.4))); } //測試加法 @Test public void testSub(){ assertEquals(new Complex(-4.3,-3.4), complex.ComplexSub(new Complex(5.3,4.4))); } //測試減法 @Test public void testMulti(){ assertEquals(new Complex(4.0,3.0), complex.ComplexMulti(new Complex(4.0,3.0))); } //測試乘法 @Test public void testDiv(){ assertEquals(new Complex(1.0,1.0), complex.ComplexDiv(new Complex(1.0,1.0))); assertEquals(new Complex(0.0,0.0), complex.ComplexDiv(new Complex(1.0,0.0))); //assertEquals(new Complex(0.0,0.0), complex.ComplexDiv(new Complex(3,4))); //邊緣測試 } @Test public void testequals(){ assertEquals(true, complex.equals(new Complex(1.0,1.0))); } //測試判斷相等 }
原代碼爲:
函數
class A { final double PI=3.1415926;// PI是常量 public double getArea(final double r) { return PI*r*r; } public final void speak() { System.out.println("您好,How's everything here ?"); } } public class Example5_9 { public static void main(String args[]) { A a=new A(); System.out.println("面積:"+a.getArea(100)); a.speak(); } }
對類名以及變量名進行重構
工具
進行封裝
重構後的代碼爲:單元測試
/** * @author Jason Tong * @date 2019/4/29 16:53. */ class Calculate { final double PI=3.1415926;// PI是常量 private int r; public double getArea() { return PI* getR() * getR(); } public final void speak() { System.out.println("您好,How's everything here ?"); } public int getR() { return r; } public void setR(int r) { this.r = r; } } public class Example5_9 { public static void main(String args[]) { Calculate a=new Calculate(); a.setR(10); System.out.println("面積:"+a.getArea()); a.speak(); } }
用java實現凱撒密碼
代碼爲:學習
/** * @author Jason Tong * @date 2019/5/3 16:58. */ public class Caesar { public static void main(String args[]) throws Exception{ String s=args[0]; int key=Integer.parseInt(args[1]); Movement m=new Movement(); int n=s.length(); String es=""; for(int i=0;i<s.length();i++){ char c=s.charAt(i); if(c >= 'a' && c <= 'z'){ es=m.realizeMove(n,c,key,'a','z'); } else if (c >= 'A' && c <= 'Z'){ es=m.realizeMove(n,c,key,'A','Z'); } } System.out.println(es); } }
/** * @author Jason Tong * @date 2019/5/3 16:59. */ public class Movement { String es=""; public String realizeMove(int n,char c,int key,char a,char b){ //移動key%26位 c+=key%26; if(c<a) { c+=26; //向左超界 } if(c>b) { c-=26; //向右超界 } es+=c; return es; } }
File>Setting>Editor>File and Code Template
按照下圖輸入開發者信息,新建類時自動添加信息。完成代碼規範
測試
解決辦法二: 根據命令行提示,代表身份信息,便可推送
優化
血淚教訓!!! 修改博客隨筆時必定要及時備份!!常常記得git pull
!!!
https://blog.csdn.net/weixin_42254058/article/details/81219931
http://www.cnblogs.com/rocedu/p/4795776.html