20155327 Experiment 3 Agile Development and XP Practice

20155327 Experiment 3 Agile Development and XP Practice

Experimental content

task one

Refer to http://www.cnblogs.com/rocedu/p/6371315.html#SECCODESTANDARD to install the alibaba plugin to solve the specification problem in the code.
Use the tool (Code->Reformate Code) in IDEA to reformat the following code, and then study the Code menu to find a function that makes you feel the best. Submit a screenshot and add your student ID watermark.

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));
    }
}

coding standard

Programming standards include: declarative names, clear expressions, straightforward control flow, readable code and comments, and the importance of using certain rules and idioms consistently when pursuing these.

General naming rules in Java:

To reflect their respective meanings Use nouns for
packages, classes and variables Use verb objects
for method names Use
all lowercase package names, such as: io, and
the first letter of awt class names should be capitalized, such as: HelloWorldApp
variable name The first letter should be lowercase, such as:
The first letter of the userName method name should be lowercase: setName

Experimental procedure

1. Open IDEA, enter alibaba in the search box in Settings → Plugins → Browse repositories... to
see the Alibaba Java Code Guidelines plugin, click Install to install, and then restart the IDE to take effect

2. Create a new class: CodeStandard.java, enter the code given in the question,
use the tool Code → Reformate Code, and modify and format the code according to the prompts

3. Understand the functions of the Code menu
Several commonly used functions are summarized as follows:

  • Override Methods(Ctrl+O): Override the methods of the base class;
  • Implement Methods(Ctrl+I): Complete the method of the interface of the current class implements (or abstract base class);
  • Generate(Alt+Insert): Create getter and setter methods for any field in the class;
  • Surround With(Ctrl+Alt+T): Wrap code snippets with if-else, try-catch, do-while, etc.;
  • Insert Live Template(Ctrl-J): Execute some unremembered Live Template abbreviations;
  • Comment with Line Comment(Ctrl+slash)/Comment with Block Comment(Ctrl+Shift+slash): Use Ctrl+slash and Ctrl-Shift-/ to comment (or uncomment) lines and blocks of code. Comment (or uncomment) the current line or selected block of code with - Ctrl+slash single-line comment marker (" //... "). Ctrl+Shift+slash, on the other hand, encloses the selected block with block comment markers ("/* */"). To uncomment a code block, press Ctrl+Shift+slash anywhere in the block;
  • Reformat Code(Ctrl+Alt+L): Indent the code according to the standard format;

Second, agile development and XP
pair programming is an important practice in XP. In the pair programming model, a pair of programmers develop work side by side, equally and complementary. They sit side by side at a computer, face the same monitor, use the same keyboard, and work together with the same mouse. They analyze together, design together, write test cases together, code together, do unit testing together, do integration testing together, write documentation together, etc.

task two

Add your learning partner to your own project on the code cloud. After confirming that your partner's project has been added to your own, download the Complex code of partner experiment 2, add no less than three JUnit unit test cases, and git add .; git commit after the test is successful -m "Add content to your student ID"; git push;

Submit a screenshot of the partner project git log, including the above git commit information, and add your own student number watermark information.

Experimental procedure

1. Download the Complex code and add the unit test case
Complex code:

public class Complex {
    // 定义属性并生成getter,setter
    double RealPart;
    double ImagePart;

    // 定义构造函数
    public Complex(double R, double I) {
        this.RealPart = R;
        this.ImagePart = I;
    }

    ;

    public Complex() {
    }

    ;

    //Override Object
    /*public boolean equals(Object obj){

    }

    public String toString();
    //Override Object
    public boolean equals(Object obj)
    public String toString()*/


}
class FourOperations{
    // 定义公有方法:加减乘除
    //Complex a = new Complex();
    // Complex b = new Complex();

    Complex ComplexAdd(Complex a,Complex b){
        Complex answer=new Complex();
        answer.RealPart=a.RealPart+b.RealPart;
        answer.ImagePart=a.ImagePart+b.ImagePart;
        return answer;
    }
    Complex ComplexSub(Complex a,Complex b){
        Complex answer=new Complex();
        answer.RealPart=a.RealPart-b.RealPart;
        answer.ImagePart=a.ImagePart-b.ImagePart;
        return answer;
    }
    Complex ComplexMulti(Complex a,Complex b){
        Complex answer=new Complex();
        answer.RealPart=(a.RealPart*b.RealPart)-(a.ImagePart*b.ImagePart);
        answer.ImagePart=(a.RealPart*b.ImagePart)+(a.ImagePart*b.RealPart);
        return answer;
    }
    Complex ComplexDiv(Complex a,Complex b){
        Complex answer=new Complex();
        double fenmu = b.RealPart*b.RealPart+b.ImagePart+b.ImagePart;
        answer.RealPart=(a.RealPart*b.RealPart+a.ImagePart*b.ImagePart)/fenmu;
        answer.ImagePart=(a.ImagePart*b.RealPart-a.RealPart*b.ImagePart)/fenmu;
        return answer;
    }
}

unit test code

import org.junit.Test;

import static org.junit.Assert.*;

public class ComplexTest {
    @Test
    public void testComplexAdd() throws Exception {
        assertEquals(5,2+3);
        System.out.println();
    }
    @Test
    public void testComplexSub() throws Exception {
        assertEquals(6,9 - 3);
    }
    @Test
    public void testComplexMulti() throws Exception {
        assertEquals(6,2 * 3);
    }
    @Test
    public void testComplexDiv() throws Exception {
        assertEquals(2,6 / 3);
    }
}

2. The screenshot is as follows

Task three:

Complete the refactoring exercises, download your partner's code, perform at least three refactorings, submit a screenshot of the refactored code, and add your own student ID 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.
Purpose:

Add new functions;
the original functions have BUG;
improve the structure of the original program;
optimize the performance of the original system.

Experimental screenshot:

Modified code:

Task four:

1. Refer to "Java Cryptography Algorithms", complete the learning of Java cryptography related content in pairs, combined with refactoring, git, and code standards.
2. Submit the cloud link of the learning achievement code and the screenshot of the representative achievement, with the student number watermark.
The Java security architecture is divided into 4 parts:

JCA (Java Cryptography Architecture, Java Cryptography Architecture): JCA provides basic encryption framework, such as certificate, digital signature, message digest and key pair generator.
JCE (Java Cryptography Extension, Java Encryption Extension Package): JCE is extended on the basis of JCA, and provides various encryption algorithms, message digest algorithms and key management functions. The implementation of JCE is mainly in the javax.crypto package (and its sub-packages)
JSSE (Java Secure Sockets Extension, Java Secure Sockets Extension): JSSE provides encryption based on SSL (Secure Sockets Layer, Secure Sockets Layer) Function. In the process of network transmission, information will pass through multiple hosts (it is very likely that one of them will be eavesdropped), and finally transmitted to the receiver, which is not safe. This service to ensure network communication security is provided by JSSE.
JAAS (Java Authentication and Authentication Service, Java Authentication and Security Service): JAAS provides the function of user authentication on the Java platform.

After having a general understanding of the method framework that the MD5 algorithm needs to use, I wrote pseudo-code:

/**

伪代码:
MD5算法:把一个任意长度的字节串变换成一定长的十六进制数字串
具体步骤:(1)生成MessageDigest对象
(2)传入需要计算的字符串
(3)计算消息摘要
(4)处理计算结果
/

Product Code:

import java.security.MessageDigest;

public class DigestPass{
public static String md5Encode(String inStr) throws Exception {
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
return "";
}

byte[] byteArray = inStr.getBytes("UTF-8");
byte[] md5Bytes = md5.digest(byteArray);
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < md5Bytes.length; i++) {
    int val = ((int) md5Bytes[i]) & 0xff;
    if (val < 16) {
        hexValue.append("0");
    }
    hexValue.append(Integer.toHexString(val));
}
return hexValue.toString();
}
}

test code]:

public static void main(String args[]) throws Exception {
String str = new String("amigoxiexiexingxing");
System.out.println("原始:" + str);
System.out.println("MD5后:" + md5Encode(str));
}

Experimental experience and summary

1. The benefits of version control
(1) Version control provides project-level undo functionality: nothing is finalized, and any errors must be easily rolled back.
(2) Version control allows multiple people to work on the same code, as long as certain control principles are followed.
(3) Version control systems keep a history of past modifications.
(4) The version control system supports the release of multiple software versions while developing on the main line.
(5) Version control is also a project-level time machine. You can choose any time to accurately view the situation of the project at that time.
2. Refactoring (Refactor): It is to change the internal structure of the software without changing the external behavior of the software to make it easier to read, maintain and change.
The modification method is: click the name to be changed with the mouse, select Refactor->Rename in the menu in Eclipse...

Guess you like

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