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
This class uses stack adt interface and linear node
StackADT code
public interface StackADT
{
public void push(T element);
public T pop();
public T peek();
public boolean isEmpty();
}
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;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started