Hi I am working on a practice question and I am trying to read in the number of bookings for a day and their time allocations. I would then like to take the start times of each booking and order the time slots from earliest booking to latest. So far I am to read in the number of bookings and the time slots but I am unsure of how to reorder the time slots. I have attached the code I have done thus far as well as the expected input and output
‘’’
import java.util.Scanner;
public class Bookings {
public static void main(String []args){
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the number of bookings:");
int numberOfBookings = keyboard.nextInt();
System.out.println("Enter the bookings, one per line:");
for (int i = 0; i <= numberOfBookings; i++){
String timeslots = keyboard.nextLine();
}
keyboard.close();
}
}
/*
Input:
Enter the number of bookings:
5
Enter the bookings, one per line:
9:00 am - 12:00 pm
1:00 pm - 6:00 pm
10:30 am - 2:30 pm
8:30 am - 9:00 am
8:00 am - 10:00 pm
Output:
Bookings in order of Start Time:
8:00 am - 10:00 pm
8:30 am - 9:00 am
9:00 am - 12:00 pm
10:30 am - 2:30 pm
1:00 pm - 6:00 pm
*/
‘’’