I'm trying to calculate the future time when a user inputs hours and minutes separated by a space. I'm stuck on when the user inputs minutes that calculates the future minutes to be less than 10.
For example, if the current time now is 10:04 and the user inputs 1 hour, 4 minutes, the future time SHOULD be 11:08.
Instead, I get printed 11:8
int extraHours = minutesGiven/60;
hoursGiven = hoursGiven+extraHours;
// System.out.println("hoursGiven= " + hoursGiven);
int extraMinutes = minutesGiven%60;
if((minutesNow + extraMinutes)>59){
minutesNow = minutesNow + extraMinutes-60;
}else if((minutesNow+hoursGiven)<10){
minutesNow = minutesNow + extraMinutes;
String padded = String.format("%02d" , minutesNow);
}else{
minutesNow = minutesNow + extraMinutes;
}
//calculate the future hour
int futureHours = 0;
if(minutesGiven==30){
futureHours = (hourNow + hoursGiven +1)%24;
}else{
futureHours = (hourNow + hoursGiven)%24;
}
//print the time
System.out.println("The time will be " + futureHours + ":" + minutesNow);
// LocalTime noon = LocalTime.of(12, 0); //12 hours, 0 minutes
//System.out.println("Noon printed as a LocalTime object: " + noon);