The document defines a MovieTime class that uses queues to store movie and snack entries. It prompts the user to input 3 movies and snacks, adds them to separate queues, then polls the snack queue each time the user presses 'S' until the queue is empty, at which point it notifies there are no snacks left.
The document defines a MovieTime class that uses queues to store movie and snack entries. It prompts the user to input 3 movies and snacks, adds them to separate queues, then polls the snack queue each time the user presses 'S' until the queue is empty, at which point it notifies there are no snacks left.
The document defines a MovieTime class that uses queues to store movie and snack entries. It prompts the user to input 3 movies and snacks, adds them to separate queues, then polls the snack queue each time the user presses 'S' until the queue is empty, at which point it notifies there are no snacks left.
public static void main (String[] args) { Scanner sc = new Scanner(System.in); Queue movies = new LinkedList(); Queue snack = new LinkedList(); int num = 3; for(int a = 1; a<=num; a++) { System.out.println("Enter movie " + a + " of "+num+":"); String movie = sc.nextLine(); movies.offer(movie); } for(int b = 1; b<=num; b++) { System.out.println("Enter snack " + b + " of "+num+":"); String snacks = sc.nextLine(); snack.offer(snacks); } System.out.println("Movies to watch are:" + movies); System.out.println("Snack available are" + snack); while(num>0) { num --; System.out.println("Press S each time you eat a snack"); char input = sc.next().charAt(0); snack.poll(); if (snack.isEmpty()) System.out.println("No more snack left"); else System.out.println(snack); } } }