20,182,316 Hu Park Experiment 3 report

20,182,316 Hu Park 2019-2020-1 "Object-oriented programming and data structures" lab report 3

Course: "Programming and Data Structures"
Class: 1823
Name: Hu Park
Student ID: 20182316
experiments Teacher: Johnny
experiment Date: 2019 [September 27]
Compulsory / Elective: Compulsory

1. Experimental content

  • Refer to "experiment two Java object-oriented programming": http: //www.cnblogs.com/rocedu/p/6736847.html
    experiment content
  • Download and install and use the IDEA, following the completion of the experiment (https://www.cnblogs.com/rocedu/p/6371315.html).
  1. Initial grasp of unit testing and TDD

  2. Understand and master the object-oriented three elements: (! Own to learn) encapsulation, inheritance, polymorphism

  3. Preliminary master UML modeling

  4. On completion of the cloud blue ink (1) - (5) experiments.

    2. Experimental procedure and results

    unit test

  • Writing Product code MyUtil.java
  • Writing test code MyUtilTest.java
    • project --- new --- Directory
    • test --- make directory as --- Test Source Root
  • TDD use
    • File --- settings --- plugins --- junit
    • Small bulbs --- creat test
    • File --- Project Structure
  • Test results Screenshot

TDD (Test Driven Devlopment, test-driven development)

  • Manual play the test program StringBuffer,
  • AssertEquals way to learn the error code equals (), the modified page
  • Writing test code according to the above method, were tested three cases: normal normal, unexpected Exception (> 100 / <0), boundary where the boundary (0,60,100 ...)
  • Test results Screenshot

Complex self-written programs

  • Pseudo-code (clear program purpose)
复数运算:
定义复数
定义构造函数
定义共有方法:加减乘除
  • Product Code
public class Complex {
   private double r;
   private double i;
   public Complex(){

   }
   public Complex (double c,double d){
   r=c;
   i=d;
   }
   public static double getreal(double r)
   {
       return r;
   }
   public static double getfake(double i)
   {
       return i;
   }
   public Complex complexadd(Complex c){
       return new Complex(r+c.r,i+c.i);
   }
   public Complex complexsub(Complex c){
       return new Complex(r-c.r,i-c.i);
   }
   public Complex complexcheng(Complex c){
       return new Complex(r*c.r-i*c.i,r*c.i+i*c.r);
   }
   public Complex complexchu(Complex c){
       return new Complex((r*c.r+i*c.i)/(c.r*c.r+c.i*c.i),(i*c.r-r*c.i)/(c.r*c.r+c.i*c.i));
   }
   public String toString(){
       if(i>0)
           return r+"+"+i+"i";
       else if(r==0)
           return r+"";
       else
           return r+""+i+"i";
   }

}
  • And the results of the test code

uml modeling

Cloud upload code

3. Experimental problems encountered in the process and settlement process

  • Question 1: occurs when writing test

  • Problem 1 Solution:
    • Class name when writing @Test, the following definitions must start with test, then again on the character you want, otherwise it will error
  • Question 2: At the time of writing toString method, misunderstood the meaning of the complex real and imaginary parts of the discussion, the negative front of more than a dozen "-."

  • Problem 2 Solution:

  • Question 3: Each time a method is called in the complex, you have to fight Complex.xxxx
  • Question 3 Solution: After the object is instantiated, such as
Complex c1 = new Complex(0, 4);

By then instantiated objects c1, Complex class calls the method:

assertEquals(-1.0, c1.getreal(-1.0));
  • Question 4: complex operation
  • Solution:

Sentiment

  • After the first use of the idea, found it to have advantages and disadvantages, the advantages are numerous, such as using the mouse, there are a variety of abbreviations, file more orderly, more powerful. But compared to the command line, type and number of errors occur more, and many can not read.
  • In the process of self-study in accordance blog step by step operation, to final completion, although the process is difficult, but let me have a strong sense of accomplishment in helping others and ask other people, have a great harvest.
  • Thanks sister school seniors guide, gave us great help, very grateful. (⊙ω⊙)

Reference material

Guess you like

Origin www.cnblogs.com/hp12138/p/11600702.html