/* * @topic T01405 Queue Object Demo * @brief Main driver: push and pull from the queue */ package pckg; /* First, String objects are "pushed onto" a queue of String objects, * and then "pulled off' and displayed. * * Second, Rectangle objects are "pushed onto" a queue of Rectangle objects, * and then "pulled off' and displayed. */ public class MyGenericQueueApp { public static void main(String [] args) { MyGenericQueue<String> q1 = new MyGenericQueue<String>(); q1.push("Fall River"); q1.push("New Bedford"); q1.push("Providence"); System.out.println("The queue contains " + q1.size() + " city objects\n"); System.out.println("Pulling off and displaying each object in the queue.\n"); while(q1.size( ) > 0) { System.out.println(q1.pull()); } System.out.println("\nThe queue contains " + q1.size() + " city objects\n"); //**************************************************************************** Rectangle R; //address of a rectangle object MyGenericQueue<Rectangle> rexque = new MyGenericQueue<Rectangle>(); rexque.push(new Rectangle(20,20)); rexque.push(new Rectangle(30,30)); rexque.push(new Rectangle(40,40)); rexque.push(new Rectangle(50,50)); System.out.println("The queue contains " + rexque.size() + " Rectangle objects \n"); System.out.println("Pulling off and displaying each object in the queue.\n"); while(rexque.size( ) > 0) { R = rexque.pull(); R.displayRectangle(); System.out.println(); } System.out.println("\nThe queue contains " + q1.size() + " Rectangle objects"); } } /* The queue contains 3 city objects Pulling off and displaying each object in the queue. Fall River New Bedford Providence The queue contains 0 city objects The queue contains 4 Rectangle objects Pulling off and displaying each object in the queue. Rectangle Length = 20.0 Rectangle Width = 20.0 Rectangle Length = 30.0 Rectangle Width = 30.0 Rectangle Length = 40.0 Rectangle Width = 40.0 Rectangle Length = 50.0 Rectangle Width = 50.0 The queue contains 0 Rectangle objects Press any key to continue... */