Beijing Institute of Electronic Technology (BESTI)
Real Inspection report
Lesson: Java Programming Class: 1352
Name: (by contribution size) Shang
Study No.: (Rank by contribution size) 20135202
Score: Instructor: Lou Jia Peng Experimental Date: 2015.5.8
Experiment level: Preview degree: Experiment time: 15:30-18:00
Instrument Group: Compulsory/Elective: compulsory Test number: 2
Experiment Name:Java Object-oriented programming
Experimental purposes 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. no linux linux Basic Primer (New edition) " 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, the 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 require redo , then follow the steps below to practice.
"Experimental instrument"
Name |
Model |
Number |
Pc |
TOSHIBA |
1 |
Virtual machines |
Laboratory Building |
1 |
"Experimental Content"
(a) Unit testing
(1) Three kinds of code
(2) TDD (test driven devlopment, testing-driven development)
(ii) Object-oriented three elements
(1) Abstract
(2) encapsulation, inheritance and polymorphism
(iii) Preliminary design pattern
(1) S.O.L.I.D principle
(2) mode and design mode
(3) design pattern Real Example
(iv) Practice
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.
"Experimental Steps"
1. Create a folder with the name of the study number
Experiment One:
(1) Unit test
This is a file on my computer.
Test code:
More Test code:
Test error Condition:
(2) TDD test method:
Create a source file
Create a test file
Test Cases
Implementation code:
Test run:
Error:
To correct
Success:
This condition needs to be changed:
Then it was passed:
Experiment Two:
Open Umbrello
Create a class
Save to specified folder
Inherited:
Corresponding Code:
Experiment Three:
Corresponding Code:
Four, Practice:
1. Pseudo-code:
Pseudo code:
The complex class outputs the real part, outputs the imaginary part, and outputs the complex number in the form of A+bi.
There are two variables in complex class, real part realpart and imaginary part imaginepart;
Method:
Getrealpart (int realpart); Return to the real part
Getimaginepart (int imaginepart); return imaginary part
toString (int realpart,int imaginepart), which outputs the complex number as a A+bi format.
2. Test the code:
Import Org.junit.Test;
Import Junit.framework.TestCase;
public class Mycomplextest extends TestCase {
@Test
public void Testrealpart () {
Assertequals (1, Mycomplex.getrealpart (1));
Assertequals ( -1, Mycomplex.getrealpart (-1));
Assertequals (5, Mycomplex.getrealpart (5));
Assertequals (Mycomplex.getrealpart (22));
Assertequals ( -100, Mycomplex.getrealpart (-100));
Assertequals (0, Mycomplex.getrealpart (0));
}
@Test
public void Testimaginepart () {
Assertequals (1, Mycomplex.getimaginepart (1));
Assertequals ( -1, Mycomplex.getimaginepart (-1));
Assertequals (5, Mycomplex.getimaginepart (5));
Assertequals (Mycomplex.getimaginepart (22));
Assertequals ( -100, Mycomplex.getimaginepart (-100));
Assertequals (0, Mycomplex.getimaginepart (0));
}
@Test
public void testtostring () {
Assertequals ("1+2i", mycomplex.tostring);
Assertequals ("1-4i", Mycomplex.tostring (1,-4));
Assertequals ("n", Mycomplex.tostring (19,0));
Assertequals (" -3i", Mycomplex.tostring (0,-3));
Assertequals ("0", mycomplex.tostring (0,0));
}
}
3. Product Code:
public class Mycomplex {
static int R;
static int i;
public static int Getrealpart (int realpart) {
R = Realpart;
return R;
}
public static int Getimaginepart (int imaginepart) {
i = Imaginepart;
return i;
}
public static String toString (int realpart,int imaginepart) {
if (realpart==0 && imaginepart==0)
return "0";
else if (Realpart = = 0)
return imaginepart+ "I";
else if (Imaginepart = = 0)
return realpart+ "";
Else
{
if (imaginepart>0)
return realpart+ "+" +imaginepart+ "I";
else if (imaginepart<0)
Return realpart+ "" +imaginepart+ "I";
}
return "wrong!";
}
}
"Experimental Experience"
What was difficult for me in this experiment was the realization of the last complex class, at first not knowing what complex needed to implement, and then not being familiar with the TDD approach and not knowing what to test. So at first I was a little bit more than the previous example of the test instance, but also for testing to write the source code.
Write the source code in the process of the main problems, when the output of complex numbers, if the coefficient is 1 to omit, if the real or imaginary part is 0 to omit, if the imaginary part is negative need to change the plus sign to minus, this heap of if-else the accumulation cost me a lot of time.
After turning this around, another problem is static, because I used the this keyword incorrectly in the method, causing the method to not be static, resulting in an error in the test instance where the non-static method could not be called. Then I found that I didn't need this, just to do the assignment and return it, which solved the second problem.
Another problem is that when returning a complex number in the form of A+bi, the return value is represented as a string type, while the format is guaranteed. Finally I used the + this connector to do.
In this experiment, I not only learned a lot of the principles of the development process, but also realized that their knowledge is not reliable, just simple memory, and can not ingenious, which requires me in the future learning and life more practice.
Steps |
Take |
Percentage |
Demand analysis |
10min |
13.3% |
Design |
15min |
20% |
Code implementation |
20min |
26.7% |
Test |
20min |
26.7% |
Analysis Summary |
10min |
13.3% |
Experiment two Java object-oriented programming