标签:ref cap 运行 stringbu 好用 lex out 版本控制系统 控制
setting
中找到plugins
并搜索alibaba
,点击install
进行安装编码规约扫描
就可以使用了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));}
}
}
code
中选择Reformate Code
格式化代码Override Methods(ctrl+O):重载基本类的方法
Surround With(Ctrl+Alt+T):使用if-else、for、while等语句包装代码段(这是我觉得最好用的功能之一)
Comment with Line Comment(Ctrl+/):将本行变成注释
import java.lang.Integer;
import java.util.Objects;
public class Complex {
//定义属性并生成getter,setter
double RealPart;
double ImagePart;
public double getRealPart(){
return RealPart;
}
public double getImagePart(){
return ImagePart;
}
//定义构造函数
public Complex(){
RealPart = 0;
ImagePart = 1;
}
public Complex(double R,double I){
RealPart = R;
ImagePart = I;
}
//Override Object
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 s = new String();
if (ImagePart > 0){
s = getRealPart() + "+" + getImagePart() + "i";
}
if (ImagePart == 0){
s = getRealPart() + "";
}
if(ImagePart < 0){
s = getRealPart() + "" + getImagePart() + "i";
}
if(RealPart == 0){
s = getImagePart() + "i";
}
if (RealPart==0&&ImagePart==0){
s="0";
}
return s;
}
//定义公有方法:加减乘除
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,RealPart*a.ImagePart + ImagePart*a.RealPart);
}
Complex ComplexDiv(Complex a) {
return new Complex((RealPart * a.ImagePart + ImagePart * a.RealPart) / (a.ImagePart * a.ImagePart + a.RealPart * a.RealPart), (ImagePart * a.ImagePart + RealPart * a.RealPart) / (a.RealPart * a.RealPart + a.RealPart * a.RealPart));
}
}
要测试的类getReal
、getImaginary
、toString
、equals
、complexAdd
、complexSub、complexMulti
、complexDiv```
import junit.framework.TestCase;
public class Complex_pTest extends TestCase {
Complex_p a=new Complex_p(2,3);
Complex_p b=new Complex_p(0,1);
Complex_p c=new Complex_p(-1,-2);
public void testGetReal() {
assertEquals(2.0,a.getReal());
assertEquals(0.0,b.getReal());
assertEquals(-1.0,c.getReal());
}
public void testGetImaginary() {
assertEquals(3.0,a.getImaginary());
assertEquals(1.0,b.getImaginary());
assertEquals(-2.0,c.getImaginary());
}
public void testToString1() {
assertEquals("2.0+3.0i",a.toString());
assertEquals("1.0i",b.toString());
assertEquals("-1.0-2.0i",c.toString());
}
public void testComplexAdd() {
assertEquals("2.0+4.0i",a.ComplexAdd(b).toString());
assertEquals("1.0+1.0i",a.ComplexAdd(c).toString());
assertEquals("-1.0-1.0i",b.ComplexAdd(c).toString());
}
public void testComplexSub() {
assertEquals("2.0+2.0i",a.ComplexSub(b).toString());
assertEquals("1.0+3.0i",b.ComplexSub(c).toString());
assertEquals("-3.0-5.0i",c.ComplexSub(a).toString());
}
public void testComplexMulti() {
assertEquals("-3.0+2.0i",a.ComplexMulti(b).toString());
assertEquals("4.0-7.0i",a.ComplexMulti(c).toString());
assertEquals("2.0-1.0i",b.ComplexMulti(c).toString());
}
public void testComplexDiv() {
assertEquals("-1.4-4.0i",a.ComplexDiv(c).toString());
assertEquals("-0.2-1.0i",b.ComplexDiv(c).toString());
}
}
然后将测试代码传到搭档的码云里,git log如下:
重构1:添加作者和日期
重构2:对类中的变量和方法进行封装
重构3:规范方法名(首字母小写)
/*
* @author dwt
* @date 2019/5/3
*/
import java.lang.Integer;
import java.util.Objects;
public class Complex {
//定义属性并生成getter,setter
private double RealPart;
private double ImagePart;
public double getRealPart(){
return RealPart;
}
public double getImagePart(){
return ImagePart;
}
//定义构造函数
public Complex(){
RealPart = 0;
ImagePart = 1;
}
public Complex(double R,double I){
RealPart = R;
ImagePart = I;
}
@Override
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;
}
@Override
public String toString(){
String s = new String();
if (ImagePart > 0){
s = getRealPart() + "+" + getImagePart() + "i";
}
if (ImagePart == 0){
s = getRealPart() + "";
}
if(ImagePart < 0){
s = getRealPart() + "" + getImagePart() + "i";
}
if(RealPart == 0){
s = getImagePart() + "i";
}
if (RealPart==0&&ImagePart==0){
s="0";
}
return s;
}
//定义公有方法:加减乘除
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,RealPart*a.ImagePart + ImagePart*a.RealPart);
}
Complex complexDiv(Complex a) {
return new Complex((RealPart * a.ImagePart + ImagePart * a.RealPart) / (a.ImagePart * a.ImagePart + a.RealPart * a.RealPart), (ImagePart * a.ImagePart + RealPart * a.RealPart) / (a.RealPart * a.RealPart + a.RealPart * a.RealPart));
}
}
2018-2019-2 20175215 实验三《敏捷开发与XP实践》实验报告
标签:ref cap 运行 stringbu 好用 lex out 版本控制系统 控制
原文地址:https://www.cnblogs.com/jxxydwt1999/p/10805419.html