public class StackCompositionTest
1: // Fig. 17.12: StackCompositionTest.java
2: // Class StackCompositionTest.
3: import com.deitel.jhtp6.ch17.StackComposition;
4: import com.deitel.jhtp6.ch17.EmptyListException;
5:
6: public class StackCompositionTest
7: {
8: public static void main( String args[] )
9: {
10: StackComposition stack = new StackComposition();
11:
12: // use push method
13: stack.push( -1 );
14: stack.print();
15: stack.push( 0 );
16: stack.print();
17: stack.push( 1 );
18: stack.print();
19: stack.push( 5 );
20: stack.print();
21:
22: // remove items from stack
23: try
24: {
25: Object removedObject = null;
26:
27: while ( true )
28: {
29: removedObject = stack.pop(); // use pop method
30: System.out.printf( "%s popped\n", removedObject );
31: stack.print();
32: } // end while
33: } // end try
34: catch ( EmptyListException emptyListException )
35: {
36: emptyListException.printStackTrace();
37: } // end catch
38: } // end main
39: } // end class StackCompositionTest
40:
41:
42:
43: /**************************************************************************
44: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
45: * Pearson Education, Inc. All Rights Reserved. *
46: * *
47: * DISCLAIMER: The authors and publisher of this book have used their *
48: * best efforts in preparing the book. These efforts include the *
49: * development, research, and testing of the theories and programs *
50: * to determine their effectiveness. The authors and publisher make *
51: * no warranty of any kind, expressed or implied, with regard to these *
52: * programs or to the documentation contained in these books. The authors *
53: * and publisher shall not be liable in any event for incidental or *
54: * consequential damages in connection with, or arising out of, the *
55: * furnishing, performance, or use of these programs. *
56: *************************************************************************/