Question: Program Specifications: JAVA Now that we have a baseline understanding of abstract data types, we will be exploring a very common data structure - the

Program Specifications: JAVA

Now that we have a baseline understanding of abstract data types, we will be exploring a very common data structure - the stack. Stacks are essential in understanding how computers work; the call stack is the foundation of how computer programs run.

The stack ADT can also be leveraged to greatly simplify any program that requires a collection of items where operations only occur on one end. Before we go any further, well look at one possible way to implement a stack using a generic array.

Implement the stack ADT following the interface provided. Then, design and implement a driver class that tests all the stack operations. This test should check all edge/boundary cases, such as, what happens when you pop from an empty stack? What happens when you push to a full stack? What happens if you try to use the toString method in a variety of situations?

Lastly, create a menu driven application that tests the push, pop, and peek methods using integers.

To do:

  • Implement the stack ADT using an array to store the data. Implement the push(), pop(), peek(), isEmpty(), and length() methods as specified in the given interface below

  • Design and implement the test class according to the specifications provided.

  • At minimum, the implementation must implement the provided interface and also override the toString method.

Notes:

  • When implementing the stack, you cannot actually create an array of generic items. In other words, you cannot create an array of type T. Intuitively, you would try to do something like: T[ ] stack = new T[100]; That line of code will result in a T cannot be resolved to a type error. Instead, you have to create an array of Object items and cast it to the generic type T T[ ] stack = (T[ ]) new Object[100];

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!