20165219 "Java Programming" Experiment 3 (Agile Development and XP Practice) Experiment Report
The cover of the lab report
Course: Java Programming Class: Class 1652 Name: Wang Yanbo Student Number: 20165219 Achievement:
Instructor: Lou Jiapeng Experiment date: April 30, 2018
Experiment time: 15:45 - 17:20
Experiment No.: Experiment 3
Experiment Name: Agile Development and XP Practice
Experiment content:
XP Basics
XP Core Practices
Related tools
Experimental requirements:
1 Students who do not have Linux foundation are recommended to study the courses of "Introduction to Linux Basics (New Edition)" and "Vim Editor";
2 Complete the experiment and write the experimental report, pay attention to the experimental report focusing on the operation results, the problems encountered (tool search, installation, use, program editing, debugging, running, etc.), solutions (empty methods such as "check the network", "Ask a classmate", "read a book", etc. will all get 0 points) and analysis (what inspiration can be obtained from it, what can be gained, lessons, etc.);
3. Count your own PSP (Personal Software Process) time in the experimental report;
4 Plagiarism is strictly prohibited.
2. Experiment content and steps
(1) alibaba plugin and Code menu
Move Line/statement Down/Up: Move a line or expression down or up one line
Surround with: wrap statements with try-catch, for, if, etc.
comment with line/block comment: Turn the selected area into a comment
show reformat file dialog: automatically align according to the format
Optimize imports: optimize imports
Insert Live Template: Insert Live Template abbreviation
For example: comment with line/block comment, turn the selected part of the code into a comment
(2) Complex code to add test cases
companion code
public class Complex {
// 定义属性并生成getter,setter
private double r;
private double i;
// 定义构造函数
public Complex(double r, double i) {
this.r = r;
this.i = i;
}
public static double getRealPart(double r) {
return r;
}
public static double getImagePart(double i) {
return i;
}
//Override Object
public boolean equals(Object obj) {
Complex complex = (Complex) obj;
if (complex.r != r) {
return false;
}
if (complex.i != i) {
return false;
}
return true;
}
public String toString() {
String str = new String();
if (i == 0) str = r + "";
else if (i < 0) str = r + "" + i + "i";
else str = r + "" + "+" + i + "i";
return str;
}
// 定义公有方法:加减乘除
Complex ComplexAdd(Complex a) {
return new Complex(r + a.r, i + a.i);
}
Complex ComplexSubtract(Complex a) {
return new Complex(r - a.r, i - a.i);
}
Complex ComplexMultiply(Complex a) {
return new Complex(r * a.r - i * a.i, r * a.i + i * a.r);
}
Complex ComplexDivide(Complex a) {
return new Complex((r * a.r + i * a.i) / (a.r * a.r + a.i * a.i), (i * a.r - r * a.i) / (a.r * a.r + a.i * a.i));
}
}
Add test case
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
public class ComplexTest extends TestCase {
Complex a=new Complex(1,2);
Complex b=new Complex(-2,-1);
Complex d=new Complex(4,-2);
@Test
public void testequals(){
assertEquals(false,a.equals(b));
assertEquals(false,b.equals(c));
assertEquals(true,new Complex(1.0,2.0).equals(a));
}
@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(17,4),new Complex(3,2.5).ComplexMultiply(c));
}
@Test
public void testDivide(){
assertEquals(new Complex(0,0.5),a.ComplexDivide(c));
assertEquals(new Complex(-2,-1),b.ComplexDivide(new Complex(1,0)));
}
}
Screenshot of passing test
screenshot of git log
(3) Refactoring
Rename
You can rename classes, packages, methods, and variables to increase code readability.
Refactor
-> Encapsulate Field...
used to encapsulate member variables
Source
-> Generate toString()...
used to generate a toString method
(4) Complete the learning of Java cryptography in pairs
The key of the Caesar cipher is 3, and the algorithm is to replace the letters in the ordinary alphabet with the letters corresponding to the key
The encryption process of the Caesar cipher can be recorded as the following transformation:
c≡m+k mod n (其中n为基本字符个数)
Likewise, the decryption process can be expressed as:
m≡c+k mod n (其中n为基本字符个数)
The results are as follows:
Refactoring
Set Code and Rename to Caesar, and assign an initial value of 0 to p
3. Experimental experience
Through this experiment, I once again realized the charm of pair programming, and through learning to refactor the code, I also understood the importance of code specification and readability.
4. PSP
step | time consuming | percentage |
---|---|---|
demand analysis | 20min | 8% |
design | 60min | 25% |
Code | 120min | 50% |
test | 10min | 4% |
analysis Summary | 30min | 13% |