public class AStack 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]; } @Override public void push(E element) throws IllegalStateException { if (theSize==CAPACITY) throw new IllegalStateException("Stack Full!"); theStack[theSize++]=element; } public AStack() { this(CAPACITY); } @SuppressWarnings("unchecked") public AStack(int capacity) { theStack = (E[])new Object[capacity]; } }