20165334 Experiment 3 Agile Development and XP Practice

20165334 Experiment 3 Agile Development and XP Practice

1. Standard code

After reading Mr. Lou's blog, my understanding of standardized code is that the format of the code should have a sense of hierarchy, and the naming of identifiers such as packages, classes, variables, and methods in the code should be standardized and easy to understand.

//没有规范前
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));
}
}

After code specification

Function learning of the Code menu

  • Override Methods(Ctrl+O)Overload the methods of the base class;
  • Generate(Alt+Insert)Create getter and setter methods for any field in the class;
  • Implement Methods(Ctrl+I)Complete the method of the interface of the current class implements (or of the abstract base class);
  • Reformat Code(Ctrl+Alt+L)Indent code in standard format;

    2. Download the Complex code of partner experiment 2 and add no less than three JUnit unit test cases

    The partner's Complexproduct code is as follows

```
class Complex {
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;
}
public Complex ComplexAdd(Complex a) {
return new Complex(r + a.r, i + a.i);
}
public Complex ComplexSub(Complex a) {
return new Complex(r - a.r, i - a.i);
}
public Complex ComplexMulti(Complex a) {
return new Complex(r * a.r - i * a.i , r * a.i + i * a.r);
}
public Complex ComplexDiv(Complex a) {
return new Complex((r * a.i + i * a.r) / (a.i * a.i + a.r * a.r), (i * a.i + r * a.r) / (a.i * a.i + a.r * a.r));
}
public String toString() {
String s =" ";
if (i > 0)
s =r +"+"+ i +"i";
if (i == 0)
s =r+"";
if (i < 0)
s = r +" "+ i+"i";
return s;
}
}

```

The screenshot of the test code I made is as follows

git logScreenshot below

3. Complete the refactoring exercises, download the code of your partner, perform at least three refactorings, submit a screenshot of the refactored code, and add your own student number watermark. Submit your partner's code cloud project link.

Refactoring is to change the internal structure of the software to make it easier to read, maintain and change without changing the external behavior of the software.

The above code structure has the following problems

  • The class name does not conform to the naming rules;
  • The constant does not conform to the code specification;
  • Statements in else should have parentheses;

    After modification, as shown in the figure

Partner's code cloud link

Fourth, complete the learning of Java cryptography related content in pairs, combining refactoring, git, code standards, etc.

After learning Java cryptography related content with our partners, we learned the Java对称加密-DES算法
learning results are as follows

The first line of the running result in the figure is the Nice to meet youbyte array encoding method
, the second line is the encrypted content, and the content of the second line varies with the key.

At the same time, we implemented the cryptography Vigenere cryptographic algorithm with java. The results are as follows:

Five problems encountered in the experiment

question:

Format error always occurs when setting creator info

Solution

Set up a creator information template as shown

6. Experimental summary and experience

Through this experiment, I once again experienced the power of a team, the spark of thinking collision, and paired learning improves the learning efficiency.
Through the coding standard, I realize the programmer's pursuit of perfection, and through the learning of java and cryptography, I realize the greatness of java.

PSP (Personal Software Process) time
step time consuming percentage
demand analysis 12min 10%
design 10min 8%
Code 48min 40%
test 40min 34%
Analysis and summary 10min 8%

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325018917&siteId=291194637