1. Create a folder named LastName_FirstName in your local drive. (ex. Reyes_Mark)
2. Using NetBeans, create a Java project named MovieTime. Set the project location to your own
folder.
3. Import Scanner, Queue, and LinkedList from the java.util package.
4. Create two (2) Queue objects named movies and snacks.
5. The output shall:
5.1.Ask the user to input three (3) movies that s/he would like to watch in a cinema.
5.2.Ask the user to input three (3) snacks or beverages that s/he would like to eat or drink while
watching these movies.
5.3.Display all the movies and snacks in separate lines.
5.4.Ask the user to type S whenever s/he is done eating or drinking a 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.
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Queue<String> movies = new LinkedList<>();
Queue<String> snacks = new LinkedList<>();
System.out.println("Input three (3) movies that you would like to watch in a cinema.");
for (int i = 0; i < 3; i++) {
movies.add(in.nextLine());
}
System.out.println("Input three (3) snacks or beverages that you would like to eat or drink while.");
for (int i = 0; i < 3; i++) {
snacks.add(in.nextLine());
}
for (String movie : movies) {
System.out.println(movie);
}
for (String snack : snacks) {
System.out.println(snack);
}
while (true) {
System.out.println("Type S whenever you are done eating or drinking a snack.");
if (in.nextLine().equals("S")) {
snacks.poll();
if (!snacks.isEmpty()) {
for (String snack : snacks) {
System.out.println(snack);
}
} else {
System.out.println("No more snacks");
break;
}
}
}
}
}
Comments
Leave a comment