Skip to main content
added 88 characters in body
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

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());

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.

The Time(hour, minute, second) constructor should just call setHour(hour), setMinute(minute), and setSecond(second) to avoid code duplication.

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());

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.

To avoid code duplication, the Time(hour, minute, second) constructor should just 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());
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

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.

The Time(hour, minute, second) constructor should just call setHour(hour), setMinute(minute), and setSecond(second) to avoid code duplication.

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());