对于下面给定的类,我被要求用一个新TimeTest
类来测试这个类,该类具有doTest()
在我的类中尝试这些方法的方法Time
。我之前通过该main
方法测试过类,但我不知道如何使用类来测试类。谁能帮我开始?
public class Time {
private int minute;
private int hour;
private int totalMinute;
public Time() {
minute = 0;
hour = 0;
}
public Time(int hours, int minutes) {
setHour(hours);
setMinute(minutes);
}
private void setHour(int hours) {
if (hours < 24 && hours >= 0) {
hour = hours;
} else {
hour = 0;
}
}
private void setMinute(int minutes) {
if (minutes < 60 && minutes >= 0) {
minute = minutes;
} else {
minute = 0;
}
}
public void setTime(int hours, int minutes) {
setHour(hours);
setMinute(minutes);
}
public int getElapsedTime(Time that) {
int thisTime = this.getTotalMinutes();
int thatTime = that.getTotalMinutes();
if (thisTime > thatTime) {
return thisTime - thatTime;
}
return thatTime - thisTime;
}
private int getTotalMinutes() {
totalMinute = (hour * 60) + minute;
return totalMinute;
}
public String getAsString() {
if (hour < 10 && minute < 10) {
return "0" + hour + ":0" + minute;
} else if (hour < 10 && minute >= 10) {
return "0" + hour + ":" + minute;
} else if (hour >= 10 && minute < 10) {
return hour + ":0" + minute;
} else {
return hour + ":" + minute;
}
}
}