Question: Create a class called DropOutStack. See Figure 1 for UML. What is a drop out stack? Same thing as a regular stack, except with a

Create a class called "DropOutStack". See Figure 1 for UML.

What is a drop out stack? Same thing as a regular stack, except with a maximum capacity. Whenever a new element is added when the stack is full, the bottom-most element must be removed from the collection (see Figure 2). The new element is then inserted and the size and max capacity shouldn't change.

Be sure to keep the following stipulations in mind: You must rely on links for its underlying data structure. Tip: Reuse and modify class 'LinkedStack' since its generics and attributes are already established and are still important to have. The code within interface 'StackADT' and class 'LinearNode' should be the same as they originally were. Note: There's no 'count' attribute, however if students want to create / maintain one, that's fine. All [four] constructors serve similar purposes and should work like so: The starting value for attribute 'maxSize' will depend on what value the constructor's integer parameter is, otherwise if said parameter doesn't exist it should be 10 (by default). Important: You MUST invoke the class' own mutator method to handle said assignment operation. The constructors which have the 'T' parameter must set said element as the starting 'top' node of the collection (otherwise it should remain null). Tip: Focus on implementing the 4th constructor (the one with two parameters) and have the other constructors invoke it, using the 'this' keyword, with appropriate arguments. Don't forget that the "pop" and "peek" method MUST throw a [runtime] exception if the stack is empty. Tip: For method "push", check the capacity limit AFTER inserting the element into the collection. Hint: If the last node needs to be decoupled from the collection, then this will require us to find and modify the 'next' reference of the second-to-last node in the sequence. Here's how the "popStack" function should work: It should throw a [runtime] exception if it's parameter 'capacity' exceeds the stack's [current] size, otherwise ... It'll return an array consisting of elements that are popped from the stack (see Figure 3). Be sure to keep the same order (in the array) as it was in the stack. First is the top-most element Second is second from the top Third is third from the top etc. Tip: Invoke the "pop" method. This will greatly reduce the total amount of code needed for this function. Tip: See Figure 4 for some sample test code. The accessor and mutator methods for 'maxSize' should follow the standard template, HOWEVER, the mutator needs to throw a [runtime] exception if its parameter is LESS than the [current] number of elements within the stack.

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!