Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting from method that has a Stack
    text
    copied!<p>I have created a method that places 3 star wars tickets in a group of 7 tickets randomly to create a total of 10 tickets. I also have to create a method that will assign the ticket to the next person in "Line". When I try to print it out it throws a EmptyStackException and I am unsure as to why. Is there a way that I have to move the Stack to the main method?</p> <p>Here is my code so far and am just wondering where I have gone wrong. Please guide me in the right direction. Thank you.</p> <pre><code>import java.util.LinkedList; import java.util.Queue; import java.util.Stack; public class movieRaffle { public static void main(String[] args) { Queue&lt;String&gt; queue = new LinkedList&lt;String&gt;(); queue.offer("Megan"); queue.offer("Kate"); queue.offer("Conan"); queue.offer("Jay"); queue.offer("Bert"); queue.offer("Ernie"); queue.offer("Mickey"); queue.offer("Goofy"); queue.offer("Optimus"); queue.offer("Megatron"); Stack&lt;String&gt; ticketList = new Stack&lt;&gt;(); while(queue.size() &gt; 0) System.out.println(queue.remove() + " wins tickets to " + ticketList.pop()); } public static void ticketList() { Stack&lt;String&gt; tickets = new Stack&lt;String&gt;(); tickets.push("Olympus Has Fallen"); tickets.push("Jurassic Park"); tickets.push("The Patriot"); tickets.push("Matrix"); tickets.push("Gettysburg"); tickets.push("Gods and Generals"); tickets.push("White House Down"); tickets.add((int) (Math.random() * 10), "Star Wars"); tickets.add((int) (Math.random() * 10), "Star Wars"); tickets.add((int) (Math.random() * 10), "Star Wars"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload