

// burton rosenberg
// 7 feb 2002

public class TestArrayStack {

   public static void main(String [] args) {
   
      ReadIntegers ri = new ReadIntegers("","") ;
      System.out.println("TestArrayStack:\n  i=-1 pop") ;
      System.out.println("  i=-2 top\n  i=-3 size") ;
      System.out.println("  i=-4 isEmpty\n  else push i") ;
      System.out.println("  empty line: exit") ;
      System.out.println() ;

      Stack s = new ArrayStack(10) ;
      int i ;
      try { while ( true ) {
         i = ri.nextInteger() ; 
         try {
            switch (i) {
            case -1: System.out.print("Pop: ") ; 
                     System.out.println(s.pop()) ;
                     break ;
            case -2: System.out.print("Top: ") ;
                     System.out.println(s.top()) ;
                     break ;
            case -3: System.out.println("Size: " + s.size()) ;
                     break ;
            case -4: System.out.println("Empty: " + s.isEmpty()) ;
                     break ;
            default: 
                     System.out.println("Push: " + i ) ;
                     s.push(new Integer(i)) ;
            }
         }
         catch ( StackEmptyException see ) {
             System.out.println("StackEmptyException") ;
         }
         catch ( StackFullException see ) {
             System.out.println("StackFullException") ;
         }
      } } 
      catch ( ReadIntegersException rie ) { }
      System.out.println("Bye.") ;
   }

}

