##20165201 Experiment 2 Object-Oriented Programming
Java Object Oriented Programming-1
Experiment purpose and requirements:
- Refer to http://www.cnblogs.com/rocedu/p/6371315.html#SECUNITTEST to complete unit testing learning
- Submit the screenshots of the last three JUnit test cases (normal, error, and boundary conditions) passing. The screenshots must be drawn and watermarked, and enter your student ID.
- Test cases should contain at least normal case, error case, edge case tests
Screenshots of experiment content and results:
- Pseudo code (can be in Chinese, preferably in English~)
百分制转五分制:
如果成绩小于60,转成“不及格”
如果成绩在60与70之间,转成“及格”
如果成绩在70与80之间,转成“中等”
如果成绩在80与90之间,转成“良好”
如果成绩在90与100之间,转成“优秀”
其他,转成“错误”
- Product code (translate the pseudocode directly from Java)
public class MyUtil{
public static String percentage2fivegrade(int grade){
//如果成绩小于0,转成“错误”
if ((grade < 0))
return "错误";
//如果成绩小于60,转成“不及格”
else if (grade < 60)
return "不及格";
//如果成绩在60与70之间,转成“及格”
else if (grade < 70)
return "及格";
//如果成绩在70与80之间,转成“中等”
else if (grade < 80)
return "中等";
//如果成绩在80与90之间,转成“良好”
else if (grade < 90)
return "良好";
//如果成绩在90与100之间,转成“优秀”
else if (grade <= 100)
return "优秀";
//如果成绩大于100,转成“错误”
else
return "错误";
}
}
- unit test
public class MyUtilTest {
public static void main(String[] args) {
//测试边界情况
if(MyUtil.percentage2fivegrade(0) != "不及格")
System.out.println("test failed 1!");
else if(MyUtil.percentage2fivegrade(60) != "及格")
System.out.println("test failed 2!");
else if(MyUtil.percentage2fivegrade(70) != "中等")
System.out.println("test failed 3!");
else if(MyUtil.percentage2fivegrade(80) != "良好")
System.out.println("test failed 4!");
else if(MyUtil.percentage2fivegrade(90) != "优秀")
System.out.println("test failed 5!");
else if(MyUtil.percentage2fivegrade(100) != "优秀")
System.out.println("test failed 6!");
else
System.out.println("test passed!");
}
}
- Create a new test directory
chooseMark Directory as->Test Sources Root
create a new class
- Screenshots of all passing JUnit test cases (normal case, error case, edge case) are as follows
Java Object Oriented Programming-2
Experiment purpose and requirements:
Java Object Oriented Programming-3
Experimental topic:
Java Object Oriented Programming-4
Java Object Oriented Programming-5
Problems during the experiment
Experimental experience and summary
IDEA's programming function is much more powerful than using vim in the terminal. Many codes can be abbreviated and automatically completed! At the same time, IDEA's debug function is also more convenient and very intuitive. I have a deep understanding of it when I correct it~
step | time consuming | percentage |
---|---|---|
demand analysis | 10 | 8.3% |
design | 15 | 12.5% |
Code | 50 | 41.6% |
test | 30 | 25% |
analysis Summary | 15 | 3012.5% |