Course: Java Lab class: 201352 Name: Chi Binning No.: 20135212
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 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.
Experimental instrument:
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:
(iv) Practice
1, the use of TDD design off the implementation of the plural class complex.
(1) Pseudo-code
Plural class
Complex number = Real part + complex PART I
Sum of complex numbers = (real part added) + (sum of complex parts) I
Subtract the same truth;
Print:
Imaginary part greater than 0: "real" + "+" + "imaginary part" + "I"
Imaginary part less than 0: "real" + "imaginary part" + "I"
The imaginary part is 0: "The real part"
(2) Product Code
Complex print, add, subtract
public class Complex {
private int sh,xu;
Complex () {
this.sh=0;
this.xu=0;
}
Complex (int sh) {
This.sh=sh;
this.xu=0;
}
Complex (int sh,int Xu) {
This.sh=sh;
This.xu=xu;
}
public void Addfu (Complex p1,complex p2) {
System.out.println ("The sum of these two complex numbers is:");
this.sh=p1.sh+p2.sh;
This.xu=p1.xu+p2.xu;
Print ();
}
public void Minusfu (Complex p1,complex p2) {
System.out.println ("The difference between these two complex numbers is:");
this.sh=p1.sh-p2.sh;
This.xu=p1.xu-p2.xu;
Print ();
}
public void Outputfu () {
System.out.println ("The value of the plural is:");
Print ();
}
public void print () {
if (this.xu>0) {
System.out.println (this.sh+ "+" +this.xu+ "I");
}else if (this.xu<0) {
System.out.println (this.sh+ "" +this.xu+ "I");
}else{
System.out.println (this.sh);
}
}
}
(3) test code
2, the report of the experiment to count their own PSP (Personal software Process) time
Steps |
Take |
Percentage |
Demand analysis |
25min |
18% |
Design |
35min |
25% |
Code implementation |
30min |
21% |
Test |
30min |
21% |
Analysis Summary |
20min |
15% |
3. Summarize the benefits of unit testing
(1) Make it easy to modify test code without worrying about the test code that will affect the design.
(2) It is easier to find the problem at an early stage, the problem is not easy to accumulate, can be solved immediately.
Problems encountered:
When you use the Umbrello tool, the abstract of the created class cannot be displayed.
When the output is a character, you do not know how to do TDD unit testing.
Workaround:
After you create the class, forget to open the display in the Class option, tick the public only option.
The output is clearly defined and the output is judged.
Experiment two Java object-oriented programming _20135129 Li Yu Yu