Java Second Experiment

Source: Internet
Author: User

Course: Java Lab class: 201353 Name: Wusi No.: 2015332

Score: Instructor: Lou Jia Peng Experimental Date: 15.05.05

Experiment level: Preview degree: Experiment time:

Instrument Group: Compulsory/Elective: Elective experiment number: 2

Experiment Name: Java Object-oriented programming

Experimental purposes and requirements:

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

Experimental requirements

1. Students who do not have a Linux base are advised to start with the Linux basics (new version) Vim Editor course

2. Complete the experiment, write the experiment Report, the experiment report is published in the blog site blog, note that the experimental report is focused on the results of the operation, problems encountered (tool search, installation, use, program editing, commissioning, operation, etc.), solutions (empty methods such as "Check Network", "Ask classmates", "reading" 0 points) as well as analysis (what can be learned from it, what gains, 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.

Experimental instrument:

Name

Model

Number

Pc

1

Experiment contents, steps and experiences (attached paper):

(a) Unit testing

(1) Three kinds of code

Programming is intellectual activity, not typing, what to do before programming, how to do to think clearly to write the program, write well. With a lot of students at present, a program to open the editor to write code, I hope that students develop a habit, when you want to solve problems with the procedure, you will write three kinds of code:

    • Pseudo code
    • Product Code
    • Test code

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

(ii) Object-oriented three elements

      • + indicates public
      • #表示 protected
      • -Indicates private

(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, and the S.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)

(2) mode and design mode

A pattern is a customary solution (solution) for a particular problem (problem) under an external environment (context). The pattern must make the problem clear, explain why it is used to solve the problem, and under what circumstances it will not work, and each pattern can be reused because of its repeatability, having its own name, being able to impart it, and transplanting it into different scenarios. Patterns can be seen as expert solutions to a problem that can be reused. There are many patterns in computer science:

    • Grasp mode
    • Analysis mode
    • Software Architecture Patterns
    • Design Patterns: Created, structured, behavioral
    • Management mode: The manager Pool implementation mode
    • Interface Design Interaction Mode
    • ...

The most important thing here is the design pattern, the position of design pattern in object-oriented can be equal to the position of data structure in process programming.

(3) design pattern Real Example

    • Design pattern provides a subsystem or component for refining a software system, or a diagram between them, which describes the public rendition structure of a communication component, which can solve a design problem in a particular context.
    • (iv) Practice
    • Use TDD to design the complex to implement the plural class.
    • Pseudo code:
        • No input---The real part of the complex number is 0 and the imaginary part is 0
        • Enter only the real part---the real part of the complex is the actual part entered, the imaginary part is 0
        • Enter only the imaginary part---the real part of the complex number is 0, the imaginary part is the imaginary part entered
        • The imaginary part of the real part---the real part of the complex number and the imaginary part correspond to the actual imaginary part of the corresponding input.
        • Addition---the real part and the real part of the complex, the imaginary part and the imaginary part, namely the output P1.repart+p2.repart,p1.impart+p2.impart
        • Subtraction---The real part of the complex number is subtracted from the real part, and the imaginary part is subtracted from the imaginary part, that is, the output P1.repart-p2.repart,p1.impart-p2.impart

Product Code:

            

Package Exercise;

public class Complex {double Repart,impart;  Complex () {this.repart=0;  this.impart=0;  } Complex (double repart) {This.repart=repart;  this.impart=0;  } Complex (double repart,double impart) {This.repart=repart;  This.impart=impart;  } Complex Jia (Complex p1,complex p2) {Complex P =new Complex (P1.repart+p2.repart,p1.impart+p2.impart); return p;  } Complex Jian (Complex p1,complex p2) {Complex P =new Complex (P1.repart-p2.repart,p1.impart-p2.impart); return p;} void Print () {System.out.println ("The value of the complex number is:"), if (this.impart!=0) System.out.println (this.repart+ "+" +this.impart+ "I")  ;  else System.out.println (This.repart); }  }

Test code:

Package Exercise;

public class Test {public static void main (string[] args) {Complex c=new Complex (); Complex c1=new Complex (2,7);  Complex c2=new Complex (5,2); C1.  Print (); C2.  Print ();  System.out.println ("These two plural and for:");  System.out.println ((C.jia (c1, C2). repart+ "+" +c.jia (c1, C2). impart+ "I"). ToString ());  System.out.println ("These two complex differences are:"); System.out.println (C.jian (c1, C2). repart+ "+" +c.jian (c1, C2). impart+ "I"); }  }

Steps

Take

Percentage

Demand analysis

5

6.25%

Design

10

12.5%

Code implementation

50

62.5%

Test

10

12.5%

Analysis Summary

5

6.25%

Summarize the benefits of unit testing:

1. Unit testing can ensure project progress and optimize your design.

2. Unit test code can perform real-world data-based testing on a production environment with a simple transactional rollback capability without worrying about generating unnecessary data.

3. Unit testing can be responsible for the module function definition as clear as possible, the internal changes of the module will not affect the other modules, and the quality of the module can be stable, quantitative guarantee.

Problems encountered: None

Workaround:

Experiment Summary:

This experiment code more, difficult, spent a lot of time, during the various big and small errors, but this is also a workout for me, will be a great help to my future study.

Java Second Experiment

Related Article

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.