Java programming Experiment two Java object-oriented programming

Source: Internet
Author: User

Beijing Institute of Electronic Technology (BESTI)

Real Inspection report

Course: Java Programming Class: 1352 Name: Yang Guangxu No.: 20135233

Score: Instructor: Lou Jia Peng Experimental Date: 2015.5.8

Experiment level: Preview degree: Experiment time:

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

Experiment Name: Java Object-oriented programming

Experimental objectives and requirements: experimental content

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.

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 be placed in this directory, no study number will require redo, and then follow the following steps to practice

Experimental instrument:

Name

Model

Number

Pc

HP HP

1

Experimental steps

(a) Unit testing

Experimental results

Modify the code in the Myutil to turn the bar into green

(ii) Object-oriented three elements

Experimental results

Practice

Experimental steps

1 use TDD to design the complex to implement the plural class.
2. Report the time of your PSP (Personal software Process)
3. Implement to have pseudo-code, product code, test code.
4. Summarize the benefits of unit testing

Experiment Code

Know:

1) Properties of the plural class ComplexNumber

Realpart: Real part, representing the real portion of a complex number

Imaginpart: Imaginary part, representing the imaginary part of a complex number

2) method of complexnumber of plural class

ComplexNumber () constructor, set the real part, the imaginary part to 0

ComplexNumber (Double R, double i) constructor to create complex objects while completing real parts of complex numbers, initialization of imaginary parts

Getrealpart () get the real part

Getimaginarypart () Get imaginary part

Getrealpart (double D) setting the real part

Getimaginarypart (double D) Set imaginary part

Add (ComplexNumber c) Complex sum

Add (double c) Add complex number

Minus (ComplexNumber c) Complex subtraction

Minus (double c) subtraction of complex numbers

Complexmulti (ComplexNumber c) Multiply plural

Complexmulti (double c) multiplication of complex numbers

ToString () combines the real part of the current complex object with the imaginary part into a a+bi string form

Pseudo code:
Plural class
Class has imaginary part real part
Addition operations of complex numbers;
subtraction of complex numbers;
multiplication of complex numbers;
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 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;
}

}

}

}

Steps

Take

Percentage

Demand analysis

30min

21%

Design

20min

14%

Code implementation

1h

42%

Test

30min

21%

Analysis Summary

Unit tests detect whether the code has bugs, where problems may occur, and cell detection finds the problem very fast.

Experimental Harvest

The use of virtual machines is more familiar, but also familiar with the use of unit detection, the future code should try to avoid the occurrence of bugs, that is, the experiment time is a bit long

Java programming Experiment two Java object-oriented programming

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.