20135337 Zhu Hui Tong Java Experiment Report Two

Source: Internet
Author: User

Experiment two Java object-oriented programming

First, the contents of the experiment

1. Initial mastery of unit testing and TDD

2. understanding and mastering the object-oriented three elements: encapsulation, inheritance, polymorphism

3. Initial Mastery of UML Modeling

4. familiarity with s.o.l.i.d principles

5. Understanding Design Patterns

Second, the experimental requirements

1. no linux Linux Basic Primer (new version) " Vim editor   Courses

2. complete the experiment, write the experiment Report, the experiment report is published in the blog garden, note that the experiment report focuses on the running results, the problems encountered ( tool find, installation, use, program editing, debugging, running, etc. ), Solutions (empty methods such as " Check the network "," ask classmates "," reading " and so on 0 points) and analysis (from which can get what revelation, what harvest, lessons, etc.). The report can refer to the guidance of Fan Fei Dragon Teacher

3. plagiarism is strictly forbidden, and the results of the experiment of the perpetrator are zero, and other punitive measures are added.

4. Please first in the laboratory building in the ~/code directory with their own school number to create a directory, code and UML diagram to put in this directory, no study number will be required to redo, and then follow the following steps to practice .

Third, the experimental steps

(a) Unit testing

(1) Three kinds of code

Pseudo-code, product code, test code

(2) TDD (test driven devlopment, testing-driven Development )

(1) A. Write the test code first, then write the product Code development method called " test-driven development "(TDD). The general steps for TDD are as follows:

    • Clear the current functionality to be completed and record it as a test list
    • Quick completion of writing test cases for this feature
    • Test code compilation does not pass (no product code)
    • Write the Product Code
    • Test Pass
    • Refactor the code and ensure the test passes (refactoring the next lab session)
      • Cycle through the development of all functions

b. Based on We're not going to be over-engineered, Requirements are expressed through test cases, and our product code can be passed as long as the test passes.   There are unit test tools Span style= "Font-family:verdana;" >junit TDD ,  

Red Fork Description Code There is a syntax error, the reason is very simple, themyutil class does not exist, the Percentage2fivegrade method in the class does not exist, we Create a new Myutil class in the SRC directory of Tdddemo , and implement Percentage2fivegrade Method

C. The test results showed a green bar, indicatingthat the test passed.

(2) The coding rhythm of TDD is:

Add test code, JUnit appears red bar , modify product code, JUnit appears green bar, Task complete

(ii) Object-oriented three elements

(1) abstract

(2) encapsulation, inheritance and polymorphism

(iii) Preliminary design pattern

(1)s.o.l.i.d principle

Object-oriented three elements are " encapsulation, inheritance, polymorphism ", and any object-oriented programming language will support these three elements syntactically. It is very difficult to use the three elements, especially polymorphism, with the help of abstract thinking, andthes.o.l.i.d design principle is a good guide:

    • SRP (Single Responsibility Principle, sole responsibility Principle )
    • OCP (open-closed Principle, open - closed principle )
    • LSP (Liskov substitusion Principle,liskov substitution principle )
    • ISP (Interface segregation Principle, interface separation principle )
    • DIP (Dependency inversion Principle, dependency inversion principle )

(iv) Practice

1 use TDD to design the Complex to implement the plural class .

2. report the time of your PSP (Personal software Process)

Iv. specific steps to achieve

(1)

(2)

(3)

A.

B.

(3)

(4)

(4) Implementing complex numbers

Pseudo code:

Addition and subtraction of complex numbers:

Define an integral type a as the real part;

Defines an integral type b as the imaginary part;

Define Newa as real part after operation;

Define newb as imaginary part after operation;

The addition operation returns P1;

The subtraction operation returns P2;

Output plus and minus operation results;

Product Code:

implementing the addition and subtraction of complex numbers

Class Complex

{

int A, B; A represents the real part, andb represents the imaginary part .

void complex (int a,int b) {

This.a=a;

This.b=b;

}

int Shi () {

return A;

}

int Xu () {

return b;

}

Complex Add (complex p) {

int Aa=p.shi ();

int Bb=p.xu ();

int newa=aa+a;

int newb=bb+b;

Complex p1=new complex ();

P1.complex (Newa, NEWB);

return p1;

}

Complex Sub (complex p) {

int Aa=p.shi ();

int Bb=p.xu ();

int newa=aa-a;

int newb=bb-b;

Complex p2=new complex ();

P2.complex (Newa, NEWB);

return p2;

}

}

public class comp5337{

public static void Main (string[] args) {

Complex c1=new complex ();

Complex c2=new complex ();

C1.complex (1, 2);

C2.complex (3, 1);

Complex P1=c1.add (C2);

int P1A=P1. Shi ();

int P1B=P1. Xu ();

System.out.println ("a=" +p1a+ ", bi=" +p1b+ "I");

System.out.printf (" and =%d+%di", p1a,p1b);

System.out.println ();

Complex P2=c1.sub (C2);

int P2A=P2. Shi ();

int P2B=P2. Xu ();

System.out.printf (" poor =%d-%di", p1a,p1b);

}

}

Test code:

Five,PSP Time Analysis

Steps

Take

Percentage

Demand analysis

1 hours

12.5%

Design

2 hours

25%

Code implementation

2 hours

25%

Test

2 hours

25%

Analysis Summary

1 hours

12.5%

Vi. problems encountered and their solutions

1, due to the win8 system, the virtual machine has been a problem, unable to work properly. Therefore, the Ecliose software on the computer is used . 2, the test code in the process of writing because of the knowledge is not fully familiar with, spent a lot of time, the code changes are repeated. 3 , in UML Drawing , when the first painting, forget to draw arrows, and then fill up.

Vii. Summary and experience

This experiment compared to the first experiment is very difficult, first of all, the knowledge point is far more than the last time, which requires me to the class also need to comb the theoretical knowledge to consolidate. Secondly, because of the computer system reasons, not able to use the whole virtual machine in this experiment, I am sorry, I will deal with the problem of virtual machine as soon as possible. Then, for unit testing, I think is conducive to learning, in the process of code-building to consolidate the theoretical knowledge of textbooks, let the knowledge into practice, although in the design, writing code is still not smooth, but the Java Object-oriented thinking helps to organize ideas. Through this experiment, I have a lot of lack of code design and writing, and I need to study hard in the future.

20135337 Zhu Hui Tong Java Experiment Report Two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.