QueueDemo.java.html

  1  import java.util.LinkedList;
  2  import java.util.Queue;
  3  
  4  /**
  5     This program simulates a print queue. Note that documents are printed
  6     in the same order as they are submitted. 
  7  */
  8  public class QueueDemo
  9  {
 10     public static void main(String[] args)
 11     {
 12        Queue<String> jobs = new LinkedList<String>(); 
 13        jobs.add("Joe: Expense Report #1");
 14        jobs.add("Cathy: Meeting Memo");
 15        System.out.println("Printing " + jobs.remove());
 16        jobs.add("Cathy: Purchase Order #1");
 17        jobs.add("Joe: Expense Report #2");
 18        jobs.add("Joe: Weekly Report");
 19        System.out.println("Printing " + jobs.remove());
 20        jobs.add("Cathy: Purchase Order #2");
 21  
 22        while (jobs.size() > 0)
 23        {
 24           System.out.println("Printing " + jobs.remove());
 25        }
 26     }
 27  }