实验三《Java面向对象程序设计》实验报告
实验内容
- XP基础
- XP核心实践
- IDEA工具学习
- 密码学算法基础
实验步骤
(一)Refactor/Reformat使用
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));
}
}
(二)单元测试&重构
重构Complex类的equal方法
equal判断时没有考虑Java处理浮点数产生的误差,应将a==b改为abs(a-b)<=1E-8
public class Complex { public final double eq = 1E-7;
double RealPart;
double ImagePart;
public double getRealPart() {
return RealPart;
}
public void setRealPart(double realPart) {
RealPart = realPart;
}
public double getImagePart() {
return ImagePart;
}
public void setImagePart(double imagePart) {
ImagePart = imagePart;
}
public Complex(double R, double I) {
RealPart = R;
ImagePart = I;
}
public boolean equals(Complex obj1) {
if (Math.abs(this.getRealPart () - obj1.getRealPart ()) <= eq && Math.abs(this.getImagePart () - obj1.getImagePart ())<=eq)
return true;
else return false;
}
public String toString() {
return RealPart + " + " + ImagePart + "i";
}
public Complex ComplexAdd(Complex obj) {
return new Complex ( RealPart + obj.getRealPart (), ImagePart + obj.getImagePart () );
}
public Complex ComplexSub(Complex obj) {
return new Complex ( RealPart - obj.getRealPart (), ImagePart - obj.getImagePart () );
}
public Complex ComplexMulti(Complex obj) {
return new Complex ( RealPart * obj.getRealPart () - ImagePart * obj.getImagePart (), RealPart * obj.getImagePart () + ImagePart * obj.getRealPart () );
}
}
(三)密码学算法
学习了DES和RSA加密算法,其中DES为对称加密算法,现在已经不够安全。RSA为非对称加密算法,由公钥和私钥组成,由于数学上认为对大整数快速分解质因数是困难的,所以说RSA算法目前而言还是安全的。之前和一个密码学方向的phd聊天,谈到随着量子计算机的出现,未来是有可能在相对较短的时间内实现质因数分解的,另外一个方面,也可以通过劫持随机数生成器,来实现攻击。
以上是 实验三《Java面向对象程序设计》实验报告 的全部内容, 来源链接: utcz.com/z/392467.html