/** * Implement the Stack interface from the textbook * by wrapping the standard class java.util.Stack. * * @author Yuan Chen */ public class JavaStack implements Stack { /** Implement via java.util.Stack. We only need to rename some * methods, throw some exceptions that java.util.Stack tolerates * silently, and keep track of the stack size. */ java.util.Stack s; /** Size of the stack. */ private int size; // We don't need many Javadoc comments here, because the behavior of // these methods is already documented in the Stack interface, which // we implement. Anything special about the implementation (e.g., // runtime) could be documented here. public JavaStack() { s = new java.util.Stack(); size = 0; // not strictly necessary } public int size() { return size; } public boolean isEmpty() { return s.empty(); } public Object top() { if (isEmpty()) throw new StackEmptyException("Stack is empty."); return s.peek(); } public void push (Object element) { s.push(element); // never have to throw StackFullException size++; } public Object pop() { // fill this in return null; // replace this! } }