标签:clip end ble dex 出现 www. 标准 学习 下载
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中的插件,通过Jetbrains官方仓库安装:打开 Settings
->Plugins
-> Marketplace
在搜索框输入alibaba即可看到Alibaba Java Code Guidelines
插件,点击Install进行安装,然后重启IDE生效:
编码规约扫描
:Code
菜单中选项的简单用法:
Override Methods
:重载方法/新建方法Implement Methods
:执行方法Generate
:创建类里面任何字段的getter与setter方法Surround with
:将某条语句被if、for等等封装语句括起Move Statement Down/up
:将语句下移到后一模块之后Move line down
:调换语句顺序Comment with Line/Block Comment
:两种注释Reformat Code
:将代码按标准格式缩进、管理
->仓库成员管理
->添加仓库成员
->邀请用户
atom Complex.java
和atom ComplexTest.java
/**
@author Xueying Zhang 20175227
@date 2019/4/29 12:49.
*/
public class Complex{
private double a;
private double b;
public Complex(double a, double b) {
this.a = a;
this.b = b;
}
public static double getRealPart(double a) {
return a;
}
public static double getImagePart(double b) {
return b;
}
public Complex ComplexAdd(Complex c) {
return new Complex(a + c.a, b + c.b);
}
public Complex ComplexSub(Complex c) {
return new Complex(a - c.a, b - c.b);
}
public Complex ComplexMulti(Complex c) {
return new Complex(a * c.a - b * c.b, a * c.b + b * c.a);
}
public Complex ComplexDiv(Complex c) {
return new Complex((a * c.b + b * c.a)/(c.b * c.b + c.a * c.a), (b * c.b + a * c.a)/(c.b * c.b + c.a * c.a));
}
public String toString() {
String s = " ";
if (b > 0) {
s = a + "+" + b + "i";
}
if (b == 0) {
s = a + "";
}
if (b < 0) {
s = a + " " + b + "i";
}
return s;
}
}
getRealPart
;getImagePart
;ComplexAdd
;ComplexSub
;ComplexMulti
;ComplexDiv
import junit.framework.TestCase;
import org.junit.Test;
public class ComplexTest extends TestCase {
Complex com1=new Complex(1.0,2.0);
Complex com2=new Complex(0.0,1.0);
Complex com3=new Complex(1.0,0.0);
Complex com4=new Complex(-1.0,-2.0);
public void testgetRealPart()throws Exception{//测试getRealPart方法
assertEquals(2.7,Complex.getRealPart(2.7));
assertEquals(-2.7,Complex.getRealPart(-2.7));
assertEquals(5.0,Complex.getRealPart(5.0));
assertEquals(0.0,Complex.getRealPart(0.0));
}
public void testgetImagePart()throws Exception{//测试getImagePart方法
assertEquals(2.7,Complex.getImagePart(2.7));
assertEquals(-2.7,Complex.getImagePart(-2.7));
assertEquals(5.0,Complex.getImagePart(5.0));
assertEquals(0.0,Complex.getImagePart(0.0));
}
public void testComplexAdd()throws Exception{//测试ComplexAdd方法
assertEquals("1.0+3.0i",com1.ComplexAdd(com2).toString());
assertEquals("2.0+2.0i",com1.ComplexAdd(com3).toString());
assertEquals("1.0+1.0i",com2.ComplexAdd(com3).toString());
assertEquals("0.0",com1.ComplexAdd(com4).toString());
}
public void testComplexSub()throws Exception{//测试ComplexSub方法
assertEquals("1.0+1.0i",com1.ComplexSub(com2).toString());
assertEquals("0.0+2.0i",com1.ComplexSub(com3).toString());
assertEquals("-1.0+1.0i",com2.ComplexSub(com3).toString());
assertEquals("2.0+4.0i",com1.ComplexSub(com4).toString());
}
public void testComplexMulti()throws Exception{//测试ComplexMulti方法
assertEquals("-2.0+1.0i",com1.ComplexMulti(com2).toString());
assertEquals("1.0+2.0i",com1.ComplexMulti(com3).toString());
assertEquals("0.0+1.0i",com2.ComplexMulti(com3).toString());
assertEquals("3.0 -4.0i",com1.ComplexMulti(com4).toString());
}
public void testComplexDiv()throws Exception{//测试ComplexDiv方法
assertEquals("1.0+2.0i",com1.ComplexDiv(com2).toString());
assertEquals("2.0+1.0i",com1.ComplexDiv(com3).toString());
assertEquals("1.0",com2.ComplexDiv(com3).toString());
assertEquals("-0.8 -1.0i",com1.ComplexDiv(com4).toString());
}
}
重构(Refactor),就是在不改变软件外部行为的基础上,改变软件内部的结构,使其更加易于阅读、易于维护和易于变更 。
我们要修改软件,万变不离其宗,无非就是四种动机:
需要重构的地方:
代码重复、方法过长、参数列过长、条件逻辑过度复杂、分支语句
一个完整的重构流程包括:
在本次的实验里遇到的问题和解决方法:
问题:
设置创建者信息时总是出现格式错误
设置一个创建者信息模板如图所示
通过这次实验让我再一次体会到结对学习的力量,让你很惊讶的会发现其是不只是有一条道路,结对学习让学习效率得到提高,两个人长短互补,而且督促双方学习,有效学习的时间变长。结对实验的好处是能够及时的发现自己的操作的失误及判断,避免了很多的不必要错误!最后还能够及时的改正自己的在错误 !
标签:clip end ble dex 出现 www. 标准 学习 下载
原文地址:https://www.cnblogs.com/DLuob/p/10793718.html