Beijing Institute of Electronic Technology (BESTI)
Real Inspection report
Course: Java Programming Class: 1353 Name: Li Haiyin No.: 20135329
Score: Instructor: Lou Jia Peng Experimental Date: 2015.5.7
Experiment level: Preview degree: Experiment time:
Instrument Group: Compulsory/elective: experimental serial number:
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
experiment requires
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:
Experimental steps
(a) Unit testing
Experimental results
After adding the test content, modify the code in the Myutil to turn the bar into green
(ii) Object-oriented three elements
Experimental results
(iv) 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 are used to detect if a bug is in the code, and it is quick to detect problems with unit detection where they can be considered and where problems may arise.
Experimental Harvest
This 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.
Learn unit testing, improve their ability, know to be responsible for their own code, to the other people's Code as far as possible bug, but also taught me in the future when writing programs to consider the various possibilities to improve the security of the code. Through this experiment, I also know the design pattern, I think through every Java experiment, not only improve my learning ability, increase knowledge, learn the method of learning, will be better learning in the future.
Java programming Experiment two Java object-oriented programming