20172316 2017-2018-2 "Program Design and Data Structure" Experiment 2 Report

Course: "Program Design and Data Structure"
Class: 1723
Name: Zhao
Ganchen Student ID: 20172316
Experiment Teacher: Wang Zhiqiang
Experiment Date: April 18, 2018
Compulsory/Elective: Compulsory


1. Experiment content

  • Getting started with unit testing and TDD
  • Understand and master the three elements of object-oriented: encapsulation, inheritance, polymorphism
  • Preliminary mastery of UML modeling
  • Become familiar with SOLID principles
  • Learn about design patterns
  • Complete the experiments (1)-(5) on the blue ink cloud.

2. Experimental process and results

  • Doing middle school , no matter what you are learning, it is right to finish the experiment content first. Experiments (1)-(5) are completed in order.
  • The main process: clearly see the main points and steps in the tutorial, and operate step by step. There are some problems in the middle (see below), which are not difficult problems to solve. Even some codes only need to be copied for simple operations, which can be said to be very convenient.
  • Results: A preliminary understanding of TDD and SOLID principles, the experimental results are basically correct. Inherited and used a lot, so I have become proficient a lot. Encapsulation is mainly reflected in the choice of visibility reserved words.

3. Problems encountered during the experiment and the solution process

  • Question 1: The initial capacity of StringBuffer, I vaguely remember that the initial capacity is , but the initial capacity 16found in the test is , why?StringBuffer a = new StringBuffer("ManyWordMany")28
  • Solution to problem 1: Through multi-party search (even directly looking at the StringBuffer class), it is confirmed that the initial capacity is indeed 16. Through research and observation, it is found that when I make a = "ManyWord", the capacity becomes 24, it can be seen that the meaning of "initial capacity" should be added on the basis of the given string 16.

  • Problem 2: Complex multiplication always miscalculates, using (1+i)*(1+i) the result should be 2i, but the result shows as i.
  • Problem 2 solution: look at the code, check it multiple times, it doesn't make any difference with the formula

public Complex ComplexMulti(Complex complex){

    RealPart = RealPart * complex.getRealPart() - ImagePart * complex.getImagePart();  

    ImagePar = ImagePart * complex.getRealPart() + RealPart * complex.getImagePart();

    return new Complex(RealPart, ImagePart);
}

At first glance, there is no problem, but in fact, a big mistake has been made! RealPart is redefined in the above formula, then the RealPart of the following formula should no longer obtain the value, and the calculation is wrong! Simple modification:

public Complex ComplexMulti(Complex complex){
        double a, b;
        a = RealPart * complex.getRealPart() - ImagePart * complex.getImagePart();
        b = ImagePart * complex.getRealPart() + RealPart * complex.getImagePart();
        return new Complex(a, b);
    }

solve!


Other (perception, thinking, etc.)

Everything is in the title.

References

"Java Programming and Data Structure Tutorial (Second Edition)"
"Java Programming and Data Structure Tutorial (Second Edition)" study guide

Guess you like

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