Lab report
Course: |
Java programming |
Class: |
1353 |
Name: |
Su Zhengsheng |
Student ID: |
2015333 |
Score: |
|
INSTRUCTOR: |
Lou Jiapu |
Lab Date: |
2015.5.6 |
Lab confidentiality level: |
|
Preview level: |
|
Lab time: |
~ 5: 00 |
Instrument group: |
|
Required/Optional courses: |
Required |
Lab No: |
Lab 2 |
Lab Name: |
Java Object-Oriented Programming |
Purpose: 1. Master UNIT TESTING AND TDD 2. Understand and master the three elements of object-oriented: encapsulation, inheritance, and Polymorphism 3. Preliminary understanding of UML modeling 4. Familiar with s.o.l. I. d principles 5. Understand the design mode |
Experimental instruments:
Name |
Model |
Quantity |
Laptop |
Msi gs70 |
1 |
|
|
|
|
|
|
|
|
|
|
|
|
Lab content:
I. UNIT TESTING AND TDD
Source code 1:
Public classmyutil {
Public static stringpercentage2fivegrade (INT grade ){
// If the score is less than 0, it is converted to "error"
If (Grade <0 ))
Return "error ";
// If the score is less than 60, it is converted to "fail"
Else if (Grade <60)
Return "fail ";
// If the score is between 60 and 70, it is converted to "pass"
Else if (Grade <70)
Return "pass ";
// If the score is between 70 and 80, it is converted to "medium"
Else if (Grade <80)
Return "moderate ";
// If the score is between 80 and 90, it turns into "good"
Else if (Grade <90)
Return "good ";
// If the score is between 90 and 100, it turns into "excellent"
Else if (Grade <= 100)
Return "excellent ";
// If the score is greater than 100, it is converted to "error"
Else
Return "error ";
}
}
Source code 2:
Importorg. JUnit. test;
Importjunit. Framework. testcase;
Public classmyutiltest extends testcase {
@ Test
Public void testnormal (){
Assertequals ("fail", myutil. percentage2fivegrade (55 ));
Assertequals ("pass", myutil. percentage2fivegrade (65 ));
Assertequals ("medium", myutil. percentage2fivegrade (75 ));
Assertequals ("good", myutil. percentage2fivegrade (85 ));
Assertequals ("excellent", myutil. percentage2fivegrade (95 ));
}
}
Ii. Three elements of object-oriented
(1) abstraction (2) encapsulation, inheritance and Polymorphism
Lab record:
Tutorial code 1:
Public class animaltest {
Publicstatic void main (string [] ARGs ){
Dogd = new dog ();
D. setcolor ("yellow ");
Getinfo (d );
Catc = new CAT ();
C. setcolor ("black ");
Getinfo (C );
}
Publicstatic void getinfo (DOG d ){
System. Out. println (D. tostring ());
}
Publicstatic void getinfo (cat c ){
System. Out. println (C. tostring ());
}
}
Tutorial Code 2:
Package dog;
Public class dogtest {
Publicstatic void main (string [] ARGs ){
Dogg = new dog ();
G. setcolor ("yellow ");
Getinfo ();
}
Public static void getinfo (DOG d ){
System. Out. println (D. tostring ());
}
}
Experiment code 3:
Public abstract class animal {
Private string color;
Public String getcolor (){
Return color;
}
Public void setcolor (string color ){
This. Color = color;
}
Public abstract string shout ();
}
Public class dog extends animal {
Public String shout (){
Return "Wang ";
}
Public String tostring (){
Return "the dog's color is" + this. getcolor () + ", and itshouts" + this. Shout () + "! ";
}
}
Public class cat extends animal {
Public String shout (){
Return "meow ";
}
Public String tostring (){
Return "The Cat's color is" + this. getcolor () + ", and itshouts" + this. Shout () + "! ";
}
}
Iii. Preliminary Design Model
Design Pattern provides a subsystem or component used to refine the software system, or the relationship between them. It describes the public reproduction structure of the communication component, communication components can solve a design problem in a specific context.
Experiment process:
Lab code:
// Server classes abstract class data {Abstract Public void displayvalue ();} class integer extends data {int value; INTEGER () {value = 100;} public void displayvalue () {system. out. println (value) ;}// pattern classes abstract class factory {Abstract Public Data createdataobject ();} class intfactory extends factory {public data createdataobject () {return New INTEGER () ;}}// client classes Class document {data PD; document (factory PF) {Pd = PF. createdataobject ();} public void displaydata () {PD. displayvalue () ;}// test class public class mydoc {static document D; public static void main (string [] ARGs) {d = new document (New intfactory ()); d. displaydata ();}}
Iv. Summary
PSP (personal software process) Time
Procedure |
Time consumed |
Percentage |
Requirement Analysis |
15 minutes |
5.5% |
Design |
15 minutes |
5.5% |
Code Implementation |
90 minutes |
33.3% |
Test |
120 minutes |
44.4% |
Analysis Summary |
30 minutes |
12% |
Benefits of unit testing:
"Many software errors come from the misunderstanding, negligence, or lack of understanding of module changes by programmers. How can we make the module function definition as clear as possible? Changes in the module do not affect other modules, and the module quality can be ensured stably and quantitatively? Unit testing is a very effective solution ."
Yes. Through unit testing, we can not only improve our programming logic and details, but also improve code perfection and reliability. Especially in the programming process, the Code module and the Test Module grow together to make the entire programming more logical and rigorous.
Conclusion: In this experiment, Java programming capabilities have been improved from unit testing, engineering-package-class, encapsulation, inheritance, and interfaces, which not only gives a new understanding of related software, in addition, they have better optimized their programming habits. Although it takes a long time to complete the transition from the lab building to the Windows platform through a virtual machine, it also exercises patience and tenacity while improving programming capabilities. During the experiment, I had a new understanding of Java by communicating with teachers and students.
20135333 su Zhengsheng
May 7, 2015
20135333 su Zhengsheng lab 2 lab report