πŸ”– Background Information

A stack is a data structure that follows the last-in-first-out (LIFO) principle. This means that the last element added to the stack (via the push operation) will be the first one to be removed (via the pop operation).

🎯 Problem Statement

Write a stack data structure that stores Dish objects. Like the post linked above, you can use an array β€œunder the hood”, meaning that your stack will have a maximum size.

βœ… Acceptance Criteria

  • Encapsulate your stack data structure in a class.
  • The stack should use an array structure β€œunder the hood” to store Dish objects.
  • I should be able to push and pop a Dish object to the stack data structure.
  • If I try to push an object onto the stack while it is full, I should see a message telling me the stack is full, and the stack should remain unchanged.
  • I should be able to peek at the stack structure (i.e. view the top object of the stack without removing it from the stack).
  • I should be able to get the current size of the stack via a size method (i.e. how many elements are in the stack?).

πŸ“‹ Dev Notes

  • You cannot use the built-in stack from Java in this solution.
  • You do not have to implement the Dish object from scratch. I have provided it here:

πŸ–₯️ Example Output

Your driver program that tests the stack data structure might look something like this:

πŸ“ Thought Provoking Questions

  1. Right now, your stack data structure is bounded by a maximum size since it is built on top of an array. How might you create a stack with no theoretical maximum size?
  2. Right now, your stack is restricted to store Dish objects only. How might you change your stack class to select which type of object you want it to store?

πŸ’Ό Add-Ons For the Portfolio

(One Credit) Clear Method

Create a method that clears all elements in the stack.

(Three Credits) Generic Type for Stack

Update your stack class to allow the user to specify what type of object will be stored in the stack. You can use generics to specify the type of object. The behavior of your stack should not change otherwise.

πŸ“˜ Works Cited

N/A