0% found this document useful (0 votes)
22 views1 page

Snacks Java

Uploaded by

Ana Busano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Snacks Java

Uploaded by

Ana Busano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;
import java.util.Stack;
import java.util.LinkedList;
import java.util.Queue;

public class Main {


public static void main(String[] args) {
Stack<String> snacks = new Stack<>();
snacks.push("Bangus");
snacks.push("Inasal");
snacks.push("Lumpia");
snacks.push("Patata");
snacks.push("Sweet Corn");

Queue<String> mySnacks = new LinkedList<>();

Scanner scanner = new Scanner(System.in);

System.out.println("Choose a Snack:");
for (int i = 0; i <snacks.size(); i++) {
System.out.println((i + 1) + ". " + snacks.elementAt(i));
}

System.out.print("Enter a number of a Snack: ");


int choice = scanner.nextInt();

if (choice > 0 && choice <= snacks.size()) {


String selectedSnack = snacks.elementAt(choice - 1);
mySnacks.add(selectedSnack);
System.out.println("You picked: " + selectedSnack);
System.out.println("My snacks: " + mySnacks);
System.out.print("I want to eat ");
System.out.println(mySnacks.poll());
System.out.println("Done eating");
} else {
System.out.println("Invalid choice. Please try again.");
}
}
}

You might also like