我创建了一个方法,将3张星球大战门票随机放入一组7张门票中,以创建总共10张门票。我还必须创建一个方法,将票据分配给“Line”中的下一个人。当我尝试打印出来时,会抛出EmptyStackException,我不确定原因。有没有办法将堆栈移到主方法中?从具有堆栈的方法打印
这是我的代码到目前为止,只是想知道我哪里出了问题。请指导我正确的方向。谢谢。
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class movieRaffle {
public static void main(String[] args) {
Queue<String> queue = new LinkedList<String>();
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<String> ticketList = new Stack<>();
while(queue.size() > 0)
System.out.println(queue.remove() + " wins tickets to " + ticketList.pop());
}
public static void ticketList() {
Stack<String> tickets = new Stack<String>();
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");
}
}
谢谢你的工作! – user2929005