20165205 2017-2018-2 "Java Programming" Experiment 3 Agile Development and XP Practice

20165205 2017-2018-2 "Java Programming" Experiment 3 Agile Development and XP Practice

Experimental content

Checkpoint 1:

  • Install the alibaba plugin to solve specification problems in the code
    • First add the partner to your project:
    • Then use the alibaba plugin to modify the format of the given code:

Checkpoint 2:

  • 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. The left side is the display after the partner code is cloned:
  • Download the Complex code of partner experiment 2, and add no less than three JUnit unit test cases

    . Add c4, c5, and c6 to the partner code, and add them to the code test.

Checkpoint 3:

  • Complete the practice of refactoring content, download the code of your partner, and perform at least three refactorings: I refactored the file name; since the alibaba plugin has strict format requirements, I added curly brackets after the if; and added the last An else is used in addition to other cases:

Checkpoint 4:

  • Complete a java cryptography code and refactor it to add an exception class:

Skey_DES.java

import java.io.*;
import javax.crypto.*;
public class Skey_DES{
public static void main(String args[])
        throws Exception{
    KeyGenerator kg=KeyGenerator.getInstance("DES");
    kg.init(56);
    SecretKey k=kg.generateKey( );
    FileOutputStream  f=new FileOutputStream("key1.dat");
    ObjectOutputStream b=new  ObjectOutputStream(f);
    b.writeObject(k);
     }
}

Skey_kb.java

import java.io.*;
    import java.security.*;
public class Skey_kb{
public static void main(String args[]) throws Exception{
    try {
        FileInputStream f = new FileInputStream("key1.dat");
        ObjectInputStream b = new ObjectInputStream(f);
        Key k = (Key) b.readObject();
        byte[] kb = k.getEncoded();
        FileOutputStream f2 = new FileOutputStream("keykb1.dat");
        f2.write(kb);

    // 打印密钥编码中的内容
    for(int i=0;i<kb.length;i++){
        System.out.print(kb[i]+",");
    }
    }
    catch (Exception e) {
            System.out.println(e.toString());
            e.printStackTrace();

      }
  }
}

SEnc.java

import java.io.*;
import java.security.*;
import javax.crypto.*;
public class SEnc{
public static void main(String[] args) throws Exception{
    try{
    String s="Hello World!";
    FileInputStream f=new FileInputStream("key1.dat");
    ObjectInputStream b=new ObjectInputStream(f);
    Key k=(Key)b.readObject( );
    Cipher cp=Cipher.getInstance("DES");
    cp.init(Cipher.ENCRYPT_MODE, k);

    byte ptext[]=s.getBytes("UTF8");
    for(int i=0;i<ptext.length;i++){
        System.out.print(ptext[i]+",");
    }
    System.out.println("");
    byte ctext[]=cp.doFinal(ptext);
    for(int i=0;i<ctext.length;i++){
        System.out.print(ctext[i] +",");
    }
    FileOutputStream f2=new FileOutputStream("SEnc.dat");
    f2.write(ctext);
}
catch (Exception e) {
    System.out.println(e.toString());
    e.printStackTrace();
        }
    }
}

SDer.java

import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public class SDec {
    public static void main(String[] args) throws Exception     {
     // 获取密文
     try {
            FileInputStream f = new FileInputStream("SEnc.dat");
            int num = f.available();
            byte[] ctext = new byte[num];
            f.read(ctext);
            // 获取密钥
            FileInputStream f2 = new FileInputStream("keykb1.dat");
            int num2 = f2.available();
            byte[] keykb = new byte[num2];
            f2.read(keykb);
            SecretKeySpec k = new SecretKeySpec(keykb, "DESede");
            // 解密
            Cipher cp = Cipher.getInstance("DESede");
            cp.init(Cipher.DECRYPT_MODE, k);
            byte[] ptext = cp.doFinal(ctext);
            // 显示明文
            String p = new String(ptext, "UTF8");
            System.out.println(p);
        } catch (Exception e) {
            System.out.println(e.toString());
            e.printStackTrace();
        }
    }
}

Learning Content

(1) Agile development and XP

  • Software Engineering:
  • Software engineering includes the following areas:
    • software requirements analysis
    • software design
    • software build
    • software test
    • Software maintenance
  • Common development process:
    • RUP(Rational Unified Process)
    • PSP(Personal Software Process )
    • TSP(Team Software Process )
    • Agile Process
    • ……
  • Agile Development: It is a human-centered, iterative, step-by-step development method

  • The cornerstones of XP software development are XP的活动, including:
    • coding
    • test
    • listen
    • design
  • General naming rules in Java:
    • 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) Coding standard

  • Programming standards include:
    • descriptive name
    • clear expression
    • Straightforward control flow
    • Readable code and comments
    • The importance of using certain rules and idioms consistently when pursuing these

(3) Refactoring

  • A very key premise in refactoring is " not changing the external behavior of the software ", which ensures that we will not bring new bugs to the original system while refactoring the original system, so as to ensure the safety of refactoring.
    • Four motivations for modifying software:
    • Add new features
    • The original function has bugs
    • Improve the structure of the original program
    • Optimize the performance of legacy systems

Problems encountered during the experiment and their solutions

  • Problem: After cloning the partner's code and refactoring, there is a problem when runningCannt start process,the working dirctory

  • Solution: Modify the outpath to the bin folder in File->Project Structure->Module->paths->

(4) Practical projects

Count your own PSP (Personal Software Process) time in the experimental report

step time consuming percentage
demand analysis 10min 7.7%
design 30min 23%
Code 50min 38%
test 10min 7.7%
analysis Summary 30min 23%

Guess you like

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