Question: StackADT Code: public interface StackADT { public void push(T element); public T pop(); public T peek(); public boolean isEmpty(); public int size(); } LinearNode Code:

 StackADT Code: public interface StackADT { public void push(T element); publicT pop(); public T peek(); public boolean isEmpty(); public int size(); }LinearNode Code: public class LinearNode { private LinearNode next; private T element;

public LinearNode() { this(null); } public LinearNode(T elem) { next = null;

StackADT Code:

public interface StackADT { public void push(T element); public T pop(); public T peek(); public boolean isEmpty(); public int size(); }

LinearNode Code:

public class LinearNode {

private LinearNode next; private T element;

public LinearNode() { this(null); } public LinearNode(T elem) { next = null; element = elem; } public LinearNode getNext() { return next; } public T getElement() { return element; } public void setNext(LinearNode node) { next = node; } public void setElement(T elem) { element = elem; } }

Everything should be here, please follow the UML as well as code in Java. Thanks in advance!

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. A11 [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 "pop Stack" 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. UML for 'DropOutStack' T LinearNode DropOutStack -maxSize: int > -top: LinearNode StackADT > +DropOutStack() +DropOutStack(max: int) +push(element: T) +DropOutStack(elem:T) pop(): T > +DropOutStack(elem: T, max: int) +peek(): T +PopStack(capacity: int): T) +isEmpty(): boolean +setMaxSize(max: int): void +size(): int +getMaxSize(): int Figure 1 - UML of assignment Before "push D" 3 max top B A null After 3 max top DCB DHCH null "push D" Figure 2 - Pushing an element onto a drop out stack that's full public class Test { public static void main(String[] args) { DropOutStack stack = new DropoutStack(); stack.push("A"); stack.push("B"); stack.push ("C"); Object values[] slack.popslack (2); T! for (Object X : values) System.out.print (X + System.out.println(); "); } } Output - Ho. Output - Homework... D DD Figure 4 - Testing function "popStack

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!