20165201 Experiment 3 Agile Development and XP Practice

##20165201 Experiment 3 Agile Development and XP Practice

Agile Development and XP Practice-1

Experiment purpose and requirements:

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

Screenshots of experiment content and results:

  • Code->Reformate Code
  • after reformatting

  • I found that Code->Surround with...the function is very useful. For example, if we want to change part of the logical structure of our code, add an if statement and use this function directly. Select the scope first.
  • click againCode->Surround with...
  • Select the statement to add~
  • The result is as follows

Agile Development and XP Practice-2

Experiment purpose and requirements:

  • 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.

Screenshots of experiment content and results:

  • partner's Complexcode
import java.lang.*;
public class Complex {
    // 定义属性并生成getter,setter
    public void setRealpart(double R){
        RealPart=R;
    }
    public double getRealpart(){
        return RealPart;
    }
    public void setImagePart(double I){
        ImagePart=I;
    }
    public double getImagePart(){
        return ImagePart;
    }

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

    //Override Object
    public boolean equals(Complex obj){
        if(this.getRealpart()==obj.getRealpart() && this.getImagePart()==obj.getImagePart())
            return true;
        else
            return false;
    }
    public String toString(){
        return RealPart+"+"+ImagePart+"i";
    }

    // 定义公有方法:加减乘除
    public Complex ComplexAdd(Complex a){
        return new Complex(this.RealPart+a.RealPart,this.ImagePart+a.ImagePart);
    }
    public Complex ComplexSub(Complex a){
        return new Complex(this.RealPart-a.RealPart,this.ImagePart-a.ImagePart);
    }
    public Complex ComplexMulti(Complex a){
        return new Complex(this.RealPart*a.RealPart-this.ImagePart*a.ImagePart,
                this.RealPart*a.ImagePart+this.ImagePart*a.RealPart);
    }
    public Complex ComplexDiv(Complex a){
        double x=this.RealPart;
        double y=this.ImagePart;
        double m=a.RealPart;
        double n=a.ImagePart;
        return new Complex((x*m+y*n)/(m*m+n*n),(y*m-x*n)/(m*m+n*n));
    }
}
  • Add no less than three JUnit unit test cases and the test is successful
    I added

    @Test
    public void testAdd_2(){
        assertEquals("5.0+0.0i",p3.ComplexAdd(p4).toString());
        System.out.println(p3.ComplexAdd(p4));
    }
    @Test
    public void testSub_2(){
        assertEquals("-1.0+2.0i",p3.ComplexSub(p4).toString());
        System.out.println(p3.ComplexSub(p4));
    }
    @Test
    public void testMut_2(){
        assertEquals("7.0+1.0i",p3.ComplexMulti(p4).toString());
        System.out.println(p3.ComplexMulti(p4));
    }
    @Test
    public void testDiv_2(){
        assertEquals("0.5+0.5i",p3.ComplexDiv(p4).toString());
        System.out.println(p3.ComplexDiv(p4));
    }
  • All codes are as follows

import junit.framework.TestCase;
import org.junit.Test;
public class ComplexTest extends TestCase {
    Complex p1=new Complex(1,1);
    Complex p2=new Complex(1,-1);
    Complex p3=new Complex(2,1);
    Complex p4=new Complex(3,-1);
    @Test
    public void testAdd(){
        assertEquals("2.0+0.0i",p1.ComplexAdd(p2).toString());
        System.out.println(p1.ComplexAdd(p2));
    }
    @Test
    public void testSub(){
        assertEquals("0.0+2.0i",p1.ComplexSub(p2).toString());
        System.out.println(p1.ComplexSub(p2));
    }
    @Test
    public void testMut(){
        assertEquals("2.0+0.0i",p1.ComplexMulti(p2).toString());
        System.out.println(p1.ComplexSub(p2));
    }
    @Test
    public void testDiv(){
        assertEquals("0.0+1.0i",p1.ComplexDiv(p2).toString());
        System.out.println(p1.ComplexDiv(p2));
    }
    @Test
    public void testAdd_2(){
        assertEquals("5.0+0.0i",p3.ComplexAdd(p4).toString());
        System.out.println(p3.ComplexAdd(p4));
    }
    @Test
    public void testSub_2(){
        assertEquals("-1.0+2.0i",p3.ComplexSub(p4).toString());
        System.out.println(p3.ComplexSub(p4));
    }
    @Test
    public void testMut_2(){
        assertEquals("7.0+1.0i",p3.ComplexMulti(p4).toString());
        System.out.println(p3.ComplexMulti(p4));
    }
    @Test
    public void testDiv_2(){
        assertEquals("0.5+0.5i",p3.ComplexDiv(p4).toString());
        System.out.println(p3.ComplexDiv(p4));
    }
}
  • Submit a screenshot of the partner project git log, including the above git commit information

Agile Development and XP Practice-3

Experiment purpose and requirements:

  • http://www.cnblogs.com/rocedu/p/4795776.html , the content of Eclipse is replaced 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.

Screenshots of experiment content and results:

  • The code for the partner is as follows:
import java.sql.*;

public class shm {
    public static void main(String args[]) {
        Connection con = null;
        Statement sql;
        ResultSet rs;
        float di = 50.0f;
        float gao = 50.0f;
        String country_low = "A";
        String country_high = "B";
        try {
            /* 加载JDBC_MySQL驱动 */
            Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception e) {
        }
        String uri = "jdbc:mysql://localhost:3306/world?useSSL=true";
        String user = "root";
        String password = "";
        try {
            con = DriverManager.getConnection(uri, user, password); //连接代码
        } catch (SQLException e) {
        }
        try {
            sql = con.createStatement();
            rs = sql.executeQuery("SELECT * FROM country"); //查询mess表
            while (rs.next()) {
                String name = rs.getString(2);
                float LifeExpectancy = rs.getFloat(8);
                if (LifeExpectancy < di && LifeExpectancy>0) {
                    di = LifeExpectancy;
                    country_low = name;
                }
                if (LifeExpectancy > gao) {
                    gao = LifeExpectancy;
                    country_high = name;
                }
            }
            con.close();
        }
        catch (SQLException e) {
            System.out.println(e);
        }

        System.out.printf("平均寿命最长的国家为: %s", country_high);
        System.out.printf("平均寿命最短的国家为: %s\n", country_low);
    }
}
  • The screenshot of the successful refactoring is as follows:
    (I refactored the class name shm-> Life; variable name float di = 50.0f; float gao = 50.0f;-> float low = 50.0f; float high = 50.0f;; and standardized the comments)

Agile Development and XP Practice-4

Experiment purpose and requirements:

Screenshots of experiment content and results:

  Run java Skey_DES, the file key1.dat will be generated in the current directory, the key contained in it can be used for encryption and decryption using the Triple-DES algorithm

  First create a file output stream object and specify the file name in its parameters, such as keykb1.dat. Then execute the write( ) method of the file output stream to write the contents of the byte array obtained in step 2 to the file

  The encrypted result is an array of bytes, which can be processed in various ways, such as being transmitted over the Internet, saved in a file, and so on. We save it in the file Senc.dat

  First obtain the ciphertext and secret key, and finally display the plaintext generated string

  • Screenshots of our representative results ( RSA algorithm )

Problems during the experiment

  In this experiment, we encountered two problems. When we refactored the code, the code we wrote ourselves was not standardized enough. It would be more difficult to change the code for the pairing partner, and we will need to practice more standardized in the future. The cryptographic algorithm is not familiar enough, and the cryptography class has not been covered at the time, so it is very obscure and difficult to understand.

Experimental experience and summary

  I deeply realized the benefits of paired learning, that is, two people can find out and correct each other's mistakes in time. There are so many people in a class, it is impossible to wait for the teacher to help them find them one by one, and the pairing format just makes up for this~ and partner It's a pleasure to work together~

step time consuming percentage
demand analysis 5 8.3%
design 10 16.6%
Code 20 33.3%
test 20 33.3%
analysis Summary 5 8.3%

Guess you like

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