public class ArrayStack implements StackInterface{ private static final int CAPACITY = 40; private E[] theStack; private int theSize; @Override public int size() { return theSize; } @Override public boolean isEmpty() { return theSize==0; } @Override public E pop() { if (theSize==0) return null; return theStack[--theSize]; } @Override public E top() { return theSize==0 ? null : theStack[theSize-1]; } @Override public void push(E element) throws IllegalStateException { if (theSize==CAPACITY) throw new IllegalStateException("Stack Full!"); theStack[theSize++]=element; } public ArrayStack() { this(CAPACITY); } @SuppressWarnings("unchecked") public ArrayStack(int capacity) { theStack = (E[])new Object[capacity]; } }