Question: Java Create code for this UML diagram for the class DropOutStack that also meets below requirements. Has to be a mutator and accessor for maxSize,

Java Create code for this UML diagram for the class DropOutStack that also meets below requirements.

Has to be a mutator and accessor for maxSize, mutator needs to throw a runtime exception if parameter is less than 1.

Default maxSize should be 10 or will depend on constructor's integer parameter. Returned array result of popStack is dependent on parameter's value.

top behaves same way as normal link-based stack.

popStack has one integer parameter refer to as capacity. if capacity exceeds stacks size, a runtime exception will be thrown otherwise it will return an array consisting of capacity elements.

push/pop no increment/decrement statements. Since there is no count attribute may have to use size and isEmpty in a different way.

For push check capacity limit after new element is added.

UML diagram for DropOutStack

-maxSize: int

-top: LinearNode

+DropOutStack()

+DropOutStack(max: int)

+DropOutStack(elem: T)

+DropOutStack(elem: T, max: int)

+popStack(capacity: int):T[capacity]

+setMaxSize(max: int): void

+getMaxSize(): int

Code for Interface StackADT

public interface StackADT

{

public void push(T element);

public T pop();

public T peek();

public boolean isEmpty();

}

Code for Linear Node

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;

}

}

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!