hello there,
so, i have an assignment, which asks to take the current time and ask for user input of hours and minutes and add it to the current time and display it as “future time is : XX:XX”. so far ive managed to slove most of it but when i enter more than 0 to 23 hour or more than 60 mins theres an error which i presume to be a logic error… any ideas as to the correct formatting?
import java.time.LocalTime;
import java.util.Scanner ;
public class FutureTime
{
public static void main (String[] args)
{
//gets the current time, and stores as a LocalTime object called myTime
LocalTime myTime = LocalTime.now();
Scanner sc = new Scanner(System.in);
System.out.println("Ready to calculate a future time?");
//extracts hour and minute as ints from our LocalTime object
int hour = myTime.getHour();
int minute = myTime.getMinute();
// prints the current time and promts for user input
LocalTime justHoursAndMinutes = LocalTime.of(hour, minute); //uses ints from earlier
System.out.println("Current time is: " + justHoursAndMinutes);
System.out.println("Enter a positive number of hours and minutes, separated by a space: ");
int newHours = sc.nextInt() + hour;
int newMins = sc.nextInt() + minute ;
LocalTime futureHoursAndMins = LocalTime.of(newHours , newMins);
System.out.println("Future time is: " + futureHoursAndMins);
//System.out.println("Future time is: " + newHours + ":" + newMins); IGNORE THIS
sc.close();
}
}