im unable to work out my previousSecond() in Time class.
here is my code:
}void setHour(int hour){ if (hour >= 0 && hour <= 23){ this.hour = hour; }else{ throw new IllegalArgumentException("Invalid hour!"); } }void setMinute(int minute){ if (minute >= 0 && minute <= 59){ this.minute = minute; }else { throw new IllegalArgumentException("Invalid minute!"); } }void setSecond(int second){ if (second >= 0 && second <= 59){ this.second = second; }else{ throw new IllegalArgumentException("Invalid second!"); } }public Time previousSecond(){ second--; if (second == 60){ second = 0; minute--; }if (minute == 60){ minute = 0; hour--; }if (hour == 24){ hour = 0; } return this; } }
this is the test code:
result i get is 00:00:-1 instead of 23:59:59. whats wrong with my code?