Java Lab report (Experiment II)

Source: Internet
Author: User

Lesson: Java Programming Class: 1351

Name: Wang Wei No.: 20135116

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

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

A. First create a folder in the virtual machine named after your own, to store the code in your experiment, the results of the operation and

2. Follow the instructions in the experiment to enter the code and run the results:

Do the above content, did not think that can be named with the school number. Because the network signal is not stable, exited the experiment, the following content is once again enters the experimental building to do.

(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

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 problems encountered and solutions

Problems: In the preparation of the unit test, because the network signal is not stable, often have broken network, card machine and other problems, can only wait for network recovery, or re-open the virtual machine to re-experiment, so also delayed a lot of time

Another big problem is that the test code in the process of writing because the program is not very familiar with the writing, and finally to follow the product code to write the test code, so the test code has a lot of problems, spend a lot of time to modify. Some of the writing code is ultimately not working smoothly.

Iv. Harvest of Experiments

Although the experiment took a lot of time, but I also gained a lot. First of all, through this experiment, I am more familiar with the use of virtual machines, but also more adapted to the experimental model. Unit testing also helped me to improve my ability to guide me through the process of dealing with problems that might arise, and taught me to take into account the possibilities of writing programs later to improve the security of the code.

Through this experiment, I have also come into contact with a lot of knowledge, such as TDD, although unfamiliar, it is difficult to deal with, but for me is still more eye-opener. I think that through every Java experiment, not only improve my learning ability, but also cultivate a sense of perseverance, although some difficulties, still try to do, may end up still no results, but will try.

Five, exercises

Pseudo code
Plural class
Class has imaginary part real part
Addition operations of complex numbers
Subtraction of complex numbers
Multiplication of complex numbers
Division operations 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 part
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

1h

16.7%

Design

1h 16.7%

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.