// 3. Finally, modify the implementation class ArrayStack to detect the error conditions
public class ArrayStack implements Stack{
      	public int[] item;
      	public int stackTop;
    
      	public ArrayStack(int size){
   	 	item = new int[size];      // Make array
   	 	stackTop = 0;
      	}
    
      	public void push(int x) throws StackException {
   		if (stackTop == item.length){
   	   		throw new StackException("Stack Overflow");
   	 	}
    
   	 	item[stackTop] = x;         // Store x in next slot
   	 	stackTop++;                 // Advance one slot location
      	}
    
      	public int  pop( ) throws StackException{
   		int returnItem;
   
   	 	if (stackTop == 0){
   	    		throw new StackException("Stack Underflow");
   	 	}
    
   	 	returnItem = item[stackTop-1];  // Get last stored item
   	 	stackTop--;           		// Back up one slot location
    
   	 	return returnItem;
      	}
}
