1.研究code菜单
- Move Line/statement Down/Up:将某行、表达式向下、向上移动一行
- suround with:用 try-catch,for,if等包裹语句
- comment with line/block comment:把选中它区域变成注释
- show reformat file dialog:按照格式自动对齐
- Optimize imports:可以优化imports,去除不必要的imports
- Insert Live Template:插入一些记不起来的 Live Template 缩写
2.下载搭档实验二的Complex代码,加入不少于三个JUnit单元测试用例
- 代码如下:
20155333->Complex
package exam20155333;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by dell1 on 2017/5/4.
*/
public class ComplexTest extends TestCase {
Complex a=new Complex(1,2);
Complex b=new Complex(-2,-1);
Complex c=new Complex(4,-2);
Complex d=new Complex(4,-2);
@Test
public void testequals(){
assertEquals(false,a.equals(b));
assertEquals(false,b.equals(c));
assertEquals(true,c.equals(d));
assertEquals(true,new Complex(1.0,2.0).equals(a));//新增测试用例1
}
@Test
public void testAdd(){
assertEquals(new Complex(-1,1),a.ComplexAdd(b));
assertEquals(new Complex(5,0),a.ComplexAdd(c));
}
@Test
public void testSubtract(){
assertEquals(new Complex(3,3),a.ComplexSubtract(b));
assertEquals(new Complex(-3,4),a.ComplexSubtract(c));
}
@Test
public void testMultiply(){
assertEquals(new Complex(0,-5),a.ComplexMultiply(b));
assertEquals(new Complex(8,6),a.ComplexMultiply(c));
assertEquals(new Complex(17,4),new Complex(3,2.5).ComplexMultiply(c));//新增2
}
@Test
public void testDivide(){
assertEquals(new Complex(0,0.5),a.ComplexDivide(c));
assertEquals(new Complex(-0.3,-0.4),b.ComplexDivide(c));
assertEquals(new Complex(-2,-1),b.ComplexDivide(new Complex(1,0)));//新增3
}
}
- 截图如下:
3.完成重构内容的练习
- 代码如下:
-
重构前代码:
-
重构后代码:
-
package week03;
/**
* Created by ren on 2017/3/11.
*/
class Clothes{
private String color;
private char size;
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public char getSize() {
return size;
}
public void setSize(char size) {
this.size = size;
}
@Override
public String toString() {
return "Color:" + color + ",Size:" + size;
}
}
public class Field {
public static void main(String[] args) {
Clothes sun = new Clothes();
Clothes spring = new Clothes();
sun.setColor("red");
sun.setSize('S');
spring.setColor("green");
spring.setSize('M');
System.out.println(sun.toString());
System.out.println(spring.toString());
}
}
- 截图如下:
4.Java密码学相关内容的学习
-
实现凯撒密码
-
文件key1.dat中生成的密钥
-
保存密钥编码并打印
-
用DESede加密
-
公钥私钥
-
RSA加密
-
用RES解密
-
消息摘要
-
代码形成果截图: