// Name : Matthew Reeves // Allows for the creation of a stack package ListPkg; import ExceptionPkg.EmptyListException; //extends the linked list method to create a stack public class Stack extends LinkedList { public Stack() { super ("Stack"); } public Stack(String listName) { super (listName); } //adds an object to the stack public void push(Object object) { insertAtFront(object); } //removes top element of stack public Object pop() throws EmptyListException { Object topValue=top(); if (isEmpty()) { throw new EmptyListException(); } else { removeFromFront(); } return topValue; } //allows top element on stack to be returned and printed to screen public Object top() throws EmptyListException { if (isEmpty()) { throw new EmptyListException(); } Object topValue=removeFromFront(); insertAtFront(topValue); return topValue; } }