Java Lab report (Experiment II)

Source: Internet
Author: User

Lesson: Java Programming Class: 1351

Name: Zhou Yongjie No.: 20135102

Score: Instructor: Lou Jia Peng Experimental Date: 2015.05.06

Experiment level: Preview degree: Experiment time: 14:00~20:00

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

Experiment Name: Java Object-oriented programming

Experimental purposes and 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 Garden, note that the experiment report focuses on the running results , 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 all get 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 .

Experimental instrument:

Name

Model

Number

Pc

Lenovo

1

Virtual machines

Laboratory Building

1

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 process:

(a) Unit testing

1. Take "percentile to five points" as an example, introduce three kinds of code

(1) Pseudo-code (2) Product Code (3) test code

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

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

About the use of test tools:

Open Eclipse, click File->new->java Project to create a new Tdddemo Java project;

In the Tdddemo project, put the mouse on the project name Tdddemo, right-click, select New->source folder in the pop-up menu to create a new test directory testing;

Put the mouse on the test directory, right-click, select the New->junit test case in the pop-up menu to create a new test cases class myutiltest;

Thus, according to the experimental code given, the experimental results are obtained:

(ii) Object-oriented three elements

(1) abstract (2) encapsulation, inheritance, polymorphism

Using the class diagram in UML to describe the class dog, first open the shell in the environment of the experimental building, enter Umbrello in the command line, open the UML modeling software Umbrello;

Click the class icon on the toolbar and then click in class diagram to pop up a Christmas box and enter the class name dog.

Put the mouse on the dog class, right-click, select Properties, in the popup dialog box in the display to remove the public only option;

Put the mouse on the dog class, right-click, select New->attribute, in the Pop-up dialog box, fill in the Type,name, and choose a good visibility;

Put the mouse on the dog class, right-click, select New->operation, in the Pop-up dialog box, fill in the Type,name, and choose visibility.

In UML, the property of a class can display its name, type, initialization value, and attributes can also display private,public,protected. The methods of the class can display their method names, parameters, return types, and the Private,public,protected property of the method. which

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

The operation results are as follows:

(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)

OCP is one of the most important principles in Ood, and the OCP's content is:

    • Software entities (class, modules, function, etc) should open for extension,but closed for modification.
    • Software entities (classes, modules, functions, etc.) should be open to expansion and closed to modifications.

Third, the experimental harvest

Through this experiment mastered a lot of small tricks, unit testing and the use of TDD, not only can write code also learned how to test the code. For encapsulation inheritance polymorphism, there is a deeper understanding. Able to master the use of three elements skillfully.

Master UML Modeling and learn some simple ways to use it.

In general, there are a lot of new things to know. Found himself a lot of shortcomings. There are many other areas that need improvement. The code is basically available, slightly modified. Did not save the Experimental building folder, it is half a day to respond to not come over. Drawing cards is not possible.

Iv. Exercises

Pseudo Code

The multiplication of complex numbers by the addition of complex complex numbers with the plural of the real part of a number class class The division operation of complex numbers

Product Code

public class Complexdemo {

Main Method

public static void Main (string[] a) {

Complex B = New Complex (2, 5);

Complex C = New Complex (3,-4);

System.out.println (b + "+" + c + "=" + B.add (c));

System.out.println (b + "-" + c + "=" + B.minus (c));

System.out.println (b + "*" + c + "=" + b.multiply (c));

System.out.println (b + "/" + c + "=" + B.divide (c));

}

}

Complex class

Class Complex {

Private double m;

Real Department

private double N;

Imaginary Part

Public Complex (double m, double N) {

THIS.M = m;

THIS.N = n;

}

Add

Public Complex Add (Complex c)

{

return new Complex (M + c.m, n + C.N);

}

Minus

Public Complex minus (Complex c) {

return new Complex (M-C.M, N-C.N);

}

Multiply

Public Complex Multiply (Complex c) {

return new Complex (M * c.m-n * C.N, M * C.N + n * c.m);

}

Divide

Public Complex Divide (Complex c)

{

Double d = math.sqrt (C.M * c.m) + math.sqrt (C.N * C.N); return new Complex ((M * c.m + N * C.N)/D, Math.Round ((M * c.n-n * c.m)/d));

}

Public String toString () {

String rtr_str = ""; if (n > 0) rtr_str = "(" + M + "+" + N + "I" + ")"; if (n = = 0) Rtr_str = "(" + M + ")"; if (n < 0) Rtr_str = "(" + M + n + "I" + ")";

return rtr_str;

}

}// test code

public static complextest{

public static void Main (string[] args)

{

Class Complex {

Private double m;// real part

Private double n;// imaginary part

Public Complex (double m, double N) {

THIS.M = m;

THIS.N = n;

}

Public String toString () {

String rtr_str = "";

if (n > 0) rtr_str = "(" + M + "+" + N + "I" + ")"; if (n = = 0) Rtr_str = "(" + M + ")"; if (n < 0) Rtr_str = "(" + M + n + "I" + ")";

return rtr_str;

}

}

}

}

Vi. Time Statistics

Steps Take Percentage
Demand analysis 0.5h 8.4%
Design 1.5h 25%
Code implementation 2h 33.2%
Test 1h 16.7%
Analysis Summary 1h 16.7%

Java Lab report (Experiment II)

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.