20165203 Experiment 3 Agile Development and XP Practice

20165203 Experiment 3 Agile Development and XP Practice

Task one:

1. Experimental requirements

Experiment 3 Agile Development and XP Practice ( http://www.cnblogs.com/rocedu/p/4795776.html ), the content of Eclipse is replaced with IDEA

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

2. Experimental process:

(1) After studying Mr. Lou's blog , the following points are very important:

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

②The general naming rules in Java are:

  • to reflect their meaning
  • nouns for packages, classes, variables
  • method name with verb object
  • The package name is all lowercase, such as: io, awt
  • The first letter of the class name should be capitalized, such as: HelloWorldApp
  • The first letter of the variable name should be lowercase, such as: userName
  • The first letter of the method name should be lowercase: setName
  • ...

(2) IDEA's Code menu learning:

The content in the Code menu is quite rich, and many functions can be realized by shortcut keys, which greatly facilitates our programming.

The screenshot of the Code menu is shown in the figure:

Features that I think are more commonly used:

  • Override Methods(Ctrl+O): Overload the method of the base class. (At first, I deliberately checked the meaning of this phrase in the word scallop, which is "overriding method", I guessed it should be "overloading method", tried it again, and the result was correct)

  • Implent Method(Ctrl+l): Write the interface method of the current class implements
  • Generate(Alt+Insert): Create getter and setter methods for the selected field
  • Surround With(Ctrl+Alt+T): Wrap a code segment with a statement, e.g. if-else, try-catch, , do-whileetc.
  • Unwrap\Remove: Remove all code snippets in this class.
  • Comment with Line Comment: comment the selected line of code
  • Comment with Block Comment: Insert a comment at the cursor position.
  • Reformat Code: Indent the code by formatting characters.

Task two:

Add your learning partner to your own project on the code cloud. After confirming that the partner's project is added to yourself, download the Complex code of partner experiment 2, add no less than three JUnit unit test cases, and git add .; git after the test is successful commit -m "Add content to your student number"; 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.

Partner's Complex code:

Partner's Complex test code:

Task three:

Learning ( http://www.cnblogs.com/rocedu/p/4795776.html ), replace the content of Eclipse with IDEA

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.

After reading the tutorial given by Mr. Lou, Refactorthe function is very rich, it helps us standardize the code, makes the code easier to understand, and raises a level.

The code for the partner is as follows:

Problem with partner code:

  • StudentThe encapsulation in the class is not obvious.
  • The name of the main class does not conform to the naming rules.
  • The output statement in the main class does not conform to the DRY rule.

Modified as follows:

Task four:

Refer to http://www.cnblogs.com/rocedu/p/6683948.html to complete the learning of Java cryptography related content in pairs, combining refactoring, git, and code standards .

Submit the learning outcome code cloud link and representative results screenshots, with a student ID watermark.

We chose the Caesar cipher:
our division of labor is that I am responsible for the encryption part, and my partner is responsible for the decryption part.
The pseudocode of the encryption part is as follows:

输入明文  
输入密钥  
进行移位转换  
输出密文

I write out the product code based on pseudocode:

import java.util.Scanner;

public class CaesarE {
    public static void main(String[] args) {
        System.out.print("请输入明文:");
        Scanner a=new Scanner(System.in);
        String b=a.nextLine();
        System.out.print("请输入秘钥:");
        Scanner c=new Scanner(System.in);
        int key=c.nextInt();
        Encrypt(b, key);
    }

    public static void Encrypt(String str,int k){
        String s="";
        for (int i = 0; i < str.length(); i++) {
            char c=str.charAt(i);
            if(c>='a'&&c<='z'){
                c+=k%26;
                if(c<'a')
                    c+=26;
                if(c>'z')
                    c-=26;

            }else if(c>='A'&&c<='Z'){
                c+=k%26;
                if(c<'A')
                    c+=26;
                if(c>'Z')
                    c-=26;
            }
            s+=c;
        }
        System.out.println(str+" 加密为: "+s);
    }
}  

My partner and I ran the product code as follows:

Problems encountered during the experiment:

Q1: When I was studying Task 1, when I opened Codeit, I didn't know many items in the menu, and I felt that I couldn't start.

A1:
Method 1:
I look up the meaning of the word in the word scallop, and then guess it.
For example, for override Methods, after the query is 覆盖方法, naturally 重载类的基本方法for .

Method 2:
Just try to click and see what results will come out. According to the results, the effect is deduced. Typically Surround With, try to click, and the result as shown in the figure will appear:
naturally, the if-else try-catch do-whilecode segment is wrapped with wait.

Q2: In IDEA, I didn't find the one in Elipes at first Generate toString().
A2: Later, I also found it Codein the middle , and it can also be used.GeneratetoString()

Experimental experience

This experiment gave my partner and I ample opportunities for cooperation. We experienced a relatively large cooperation. Indeed, more people are more powerful, and more people can gather firewood. All these have made us realize the meaning of pair programming.

step time consuming percentage
demand analysis 12min 10%
design 10min 8%
Code 48min 40%
test 40min 34%
analysis Summary 10min 8%

Guess you like

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