Your validation is too strict, as a minute can sometimes have 61 seconds. Limiting it to 60 seconds is what causes computer crashes during leap seconds.
TheTo avoid code duplication, the Time(hour, minute, second)
constructor should just call setHour(hour)
, setMinute(minute)
, and setSecond(second)
to avoid code duplication.do:
public Time(int hour, int minute, int second) {
this.setHour(hour);
this.setMinute(minute);
this.setSecond(second);
}
Your spacing is a bit weird here:
return String .format( "%02d:%02d:%02d", getHour(), getMinute(), getSecond());
It would be more conventional to write:
return String.format("%02d:%02d:%02d", getHour(), getMinute(), getSecond());