Stack Class Exercise
- Download the files from the StackExercise folder in Files on canvas.
- Write a toString method for the ArrayBoundedStack class. We will use
this in our test program to make sure that the stack methods are
creating a correct stack; it is not part of the ADT. The toString
method should return all
items on the stack from
bottom to top (use newlines to place each item on a separate
line, and indent the items to make it easier to read).
- Write a main method which contains a stack of Strings.
Prompt the user for the type of stack to create: default size
or specified size. If the user wants to specify the size, prompt
for the size. Create the stack and
write a loop with a menu that gives the user the following
options:
- enter a String from the keyboard and push the String onto the stack
- print the item on top of the stack
- pop an element from the stack
- print the stack
- exit
- Run your program to test the stack class. Use the menu options to
enter and remove values and make sure that all methods are
functioning correctly.
- Add a method public T TopPop() that pops and returns the
element on the top of the stack. The method should throw a
StackUnderflowException if the stack is empty.
Add a menu item to your main method
to call this function
and print the element that is returned.
Run your program to test this method.
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2017