20175333曹雅坤 实验三敏捷开发与XP实践《Java开发环境的熟悉》实验报告
敏捷开发与XP实践-1
实验目的与要求:
- 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');
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));
}
}
实验步骤
Settings
->Plugins
-> Browse repositories...
——安装alibaba。
检查代码
格式化之后
- 好用功能
实现接口方法(Implements Methods):Ctrl + I
Gengrate:Alt + Insert
Surround With:Ctrl+Alt+T
智能选择并实现(SmartType):Ctrl + Shift + 空格
方法展开 ( Expand) Ctrl + 加号
方法折叠 (Collapse)Ctrl + 减号
展开Java doc注释 ( Expand doc comments )
折叠Java doc注释 ( Collapse doc comments )
行注释 (Comment with Line Comment )Ctrl + /
块注释 ( Comment with Block Comment ) Ctrl + Shift + /
格式化代码 (Reformat Code ) Ctrl + Alt + L
重新整理代码 (Rearrange Code)敏捷开发与XP实践-2
- 在码云上把自己的学习搭档加入自己的项目中,确认搭档的项目加入自己后,下载搭档实验二的Complex代码,加入不少于三个JUnit单元测试用例,测试成功后git add .; git commit -m "自己学号 添加内容";git push;
- 提交搭档项目git log的截图,包含上面git commit的信息,并加上自己的学号水印信息。
实验步骤
- 加入仓库
- 效果
- 单元测试
- git log
- 代码
import java.text.DecimalFormat;
public class Complex {
double RealPart;
double ImagePart;
public Complex(){
}
public Complex(double R,double I){
RealPart = R;
ImagePart = I;
}
public void setter(double R,double I){
RealPart = R;
ImagePart = I;
}
public double getterRealPart(){
return RealPart;
}
public double getterImagePart(){
return ImagePart;
}
@Override
public boolean equals(Object obj){
if(this==obj){
return true;
}
else
{
return false;
}
}
@Override
public String toString(){
String s = "";
if(getterRealPart()==0&&getterImagePart()==0){
s="0";
}
else if(getterRealPart()!=0&&getterImagePart()==0){
s=s+getterRealPart();
}
else if (getterRealPart()==0&&getterImagePart()!=0){
s=s+getterImagePart()+"i";
}
else
{
if(getterImagePart()<0){
s = s+getterRealPart()+getterImagePart()+"i";
}
else {
s = s+getterRealPart()+"+"+getterImagePart()+"i";
}
}
return s;
}
public Complex ComplexAdd(Complex a){
return new Complex((getterRealPart()+a.getterRealPart()),(getterImagePart()+a.getterImagePart()));
}
public Complex ComplexSub(Complex a){
return new Complex((getterRealPart()-a.getterRealPart()),(getterImagePart()-a.getterImagePart()));
}
public Complex ComplexMulti(Complex a){
double imaginePart = getterRealPart()*a.getterImagePart()+getterImagePart()*a.getterRealPart();
double realPart = getterRealPart()*a.getterRealPart()-getterImagePart()*a.getterImagePart();
return new Complex(realPart,imaginePart);
}
public Complex ComplexDiv(Complex a) throws Exception {
double imaginePart = -getterRealPart()*a.getterImagePart()+getterImagePart()*a.getterRealPart();
double realPart = getterRealPart()*a.getterRealPart()+getterImagePart()*a.getterImagePart();
double div = a.getterRealPart()*a.getterRealPart()+a.getterImagePart()*a.getterImagePart();
if(div==0){
throw new Exception();
}
realPart = realPart/div;
imaginePart = imaginePart/div;
DecimalFormat decimalFormat = new DecimalFormat("0.0");
return new Complex(Double.valueOf(decimalFormat.format(realPart)),Double.valueOf(decimalFormat.format(imaginePart)));
}
}
敏捷开发与XP实践-3
- http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替换成IDEA
- 完成重构内容的练习,下载搭档的代码,至少进行三项重构,提交重构后代码的截图,加上自己的学号水印。提交搭档的码云项目链接。
实验内容及结果截图:
- 添加创建者信息
- 给覆写方法加上@Override注解
- 方法名,参数名,成员变量,局部变量都统一使用lowerCamelCase,遵从驼峰形式
- 规范后代码
/**
* @author caoyakun
* @date 2019/5/3
*/
import java.text.DecimalFormat;
public class Complex {
double RealPart;
double ImagePart;
public Complex() {
}
public Complex(double R, double I) {
RealPart = R;
ImagePart = I;
}
public void setter(double R, double I) {
RealPart = R;
ImagePart = I;
}
public double getterRealPart() {
return RealPart;
}
public double getterImagePart() {
return ImagePart;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else {
return false;
}
}
@Override
public String toString() {
String s = "";
if (getterRealPart() == 0 && getterImagePart() == 0) {
s = "0";
} else if (getterRealPart() != 0 && getterImagePart() == 0) {
s = s + getterRealPart();
} else if (getterRealPart() == 0 && getterImagePart() != 0) {
s = s + getterImagePart() + "i";
} else {
if (getterImagePart() < 0) {
s = s + getterRealPart() + getterImagePart() + "i";
} else {
s = s + getterRealPart() + "+" + getterImagePart() + "i";
}
}
return s;
}
public Complex ComplexAdd(Complex a) {
return new Complex((getterRealPart() + a.getterRealPart()), (getterImagePart() + a.getterImagePart()));
}
public Complex ComplexSub(Complex a) {
return new Complex((getterRealPart() - a.getterRealPart()), (getterImagePart() - a.getterImagePart()));
}
public Complex ComplexMulti(Complex a) {
double imaginePart = getterRealPart() * a.getterImagePart() + getterImagePart() * a.getterRealPart();
double realPart = getterRealPart() * a.getterRealPart() - getterImagePart() * a.getterImagePart();
return new Complex(realPart, imaginePart);
}
public Complex ComplexDiv(Complex a) throws Exception {
double imaginePart = -getterRealPart() * a.getterImagePart() + getterImagePart() * a.getterRealPart();
double realPart = getterRealPart() * a.getterRealPart() + getterImagePart() * a.getterImagePart();
double div = a.getterRealPart() * a.getterRealPart() + a.getterImagePart() * a.getterImagePart();
if (div == 0) {
throw new Exception();
}
realPart = realPart / div;
imaginePart = imaginePart / div;
DecimalFormat decimalFormat = new DecimalFormat("0.0");
return new Complex(Double.valueOf(decimalFormat.format(realPart)), Double.valueOf(decimalFormat.format(imaginePart)));
}
}
码云链接
原文地址:https://www.cnblogs.com/Hf-Hf/p/10804947.html
时间: 2024-10-17 21:20:55