package Stack_Java; public class ArrayStack { private int top; private int capacity = 100; private Object[] storage; ArrayStack() { storage = new Object[capacity]; top = -1; } void push(Object value) { if (top == storage.length) throw new StackException("Stack's underlying storage is overflow"); top++; storage[top] = value; } Object peek() { if (top == -1) throw new StackException("Stack is empty"); return storage[top]; } Object pop() { if (top == -1) throw new StackException("Stack is empty"); Object result = storage[top--]; return result; } boolean empty() { return (top == -1); } public class StackException extends RuntimeException { public StackException(String message) { super(message); } } }