我正在尝试学习一些youtube视频后的获取和设置方法。现在我们有了相同的代码,但是无论如何我都认为它与路径有关,无论如何我无法将金枪鱼解析为这里的类型错误。
我曾经尝试过弄乱构建路径,但是对我来说却没有用。
//苹果代码
public class apples {
public static void main(String[] args) {
tuna tunaObject = new tuna();
tuna tunaObject2 = new tuna(5);
tuna tunaObject3 = new tuna(5, 13);
tuna tunaObject4 = new tuna(5, 13, 43);
System.out.printf("%s\n", tunaObject.toMilitary());
}
}
//金枪鱼的代码
public class Tuna {
private int hour;
private int minute;
private int second;
/*constructor 1 */
public Tuna() {
this(0, 0, 0);
}
//constructor 2
public Tuna(int h) {
this(h, 0, 0);
}
//constructor 3
public Tuna(int h, int m) {
this(h, m, 0);
}
//constructor 4
public Tuna(int h, int m, int s) {
setTime(h, m, s);
}
public void setTime(int h, int m, int s) {
setHour(h);
setMinute(m);
setSecond(s);
}
public void setHour(int h) {
hour = ((h >= 0 && h < 24) ? h : 0);
}
public void setMinute(int m) {
minute = ((m >= 0 && m < 60) ? m : 0);
}
public void setSecond(int m) {
second = ((m >= 0 && m < 60) ? m : 0);
}
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
public int getSecond() {
return second;
}
public String toMilitary() {
return String.format("%02d:%02d:%02d", getHour(), getMinute(), getSecond());
}
}