Answer to Question #280104 in Java | JSP | JSF for Jay

Question #280104

Create a folder named LastName_FirstName in your local drive. (ex. Reyes_Mark)

  1. Using NetBeans, create a Java project named MovieTime. Set the project location to your own folder.
  2. Import Scanner, Queue, and LinkedList from the java.util package.
  3. Create two (2) Queue objects named movies and snacks.
  4. The output shall:

5.1 Ask the user to input three (3) movies that he would like to watch in a cinema

5.2 Ask the user to input three (3) snacks or beverages that he would like to eat while watching

5.3 Display all the movies and snacks in separate lines.

5.4 Ask the user to type S whenever he is done eating or drinking snack

5.5 Display the snacks remaining each time S is pressed and "No more snacks" when all snacks are eaten

6. Convert your code into a Python script

7.Save the script as movie_time.py to your folder


1
Expert's answer
2021-12-15T16:23:09-0500
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class MovieTime {
    public static void main(String[] args) {
        Queue<String> movies = new LinkedList<>();
        Queue<String> snacks = new LinkedList<>();
        Scanner in = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println((i + 1) + " Movie: ");
            movies.add(in.nextLine());
        }
        for (int i = 0; i < 3; i++) {
            System.out.println((i + 1) + " Snack or beverage: ");
            snacks.add(in.nextLine());
        }
        for (String movie : movies) {
            System.out.println(movie);
        }
        System.out.println();
        for (String snack : snacks) {
            System.out.println(snack);
        }
        while (!snacks.isEmpty()) {
            System.out.println("type S");
            if (in.nextLine().equals("S")) {
                snacks.poll();
                System.out.println();
                for (String snack : snacks) {
                    System.out.println(snack);
                }
            }
        }
        System.out.println("No more snacks");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog