Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Draw the UML diagram of your VectorStack , place it in the correct spot in the UML Class Diagram given. Do not forget to draw

Draw the UML diagram of your VectorStack, place it in the correct spot in the UML Class Diagram given. Do not forget to draw the relations between your VectorStack and other classes (arrows).

StackInterface.java:

public interface StackInterface {

public T pop() throws StackUnderflowException;

public T top();

public boolean isEmpty();

}

BoundedStackInterface.java:

public interface BoundedStackInterface extends StackInterface {

public void push(T element) throws StackOverflowException;

public boolean isFull();

}

UnboundedStackInterface.java:

public interface UnboundedStackInterface extends StackInterface{

public void push(T element);

}

ArrayStack.java:

@SuppressWarnings("unchecked")

public class ArrayStack implements BoundedStackInterface {

protected final int DEFCAP = 100;

protected T[] stack;

protected int numElements = 0;

public ArrayStack() {

stack = (T[]) new Object[DEFCAP];

}

public ArrayStack(int maxSize) {

stack = (T[]) new Object[maxSize];

}

public void push(T element) throws StackOverflowException {

if (isFull())

throw new StackOverflowException("Enqueue attempted on a full stack.");

else {

stack[numElements] = element;

numElements = numElements + 1;

}

}

public T pop() throws StackUnderflowException {

if (isEmpty())

throw new StackUnderflowException(

"Dequeue attempted on empty stack.");

else {

numElements--;

T toReturn = stack[numElements];

return toReturn;

}

}

public boolean isEmpty() {

return (numElements == 0);

}

public boolean isFull() {

return (numElements == stack.length);

}

@Override

public T top() {

if (isEmpty())

return null;

else

return stack[numElements - 1];

}

}

LinkedStack.java:

import java.util.LinkedList;

public class LinkedStack implements UnboundedStackInterface{

LinkedList list;

public LinkedStack() {

list = new LinkedList();

}

public void push(T s) {

// add at back

list.add(s);

}

public T pop() throws StackUnderflowException {

if (isEmpty())

throw new StackUnderflowException(

"Dequeue attempted on empty stack.");

// remove from end

return list.removeLast();

}

public boolean isEmpty() {

return (list.size() == 0);

}

public boolean isFull() {

return false;

}

@Override

public T top() {

if(isEmpty())

return null;

else

return list.getLast();

}

}

StackUnderflowException.java:

public class StackUnderflowException extends Exception {

public StackUnderflowException(String string) {

super(string);

}

public StackUnderflowException() {

super();

}

}

StackOverflowException.java:

public class StackOverflowException extends Exception {

public StackOverflowException(String string) {

super(string);

}

public StackOverflowException() {

}

}

image text in transcribed

> Stackinterface StackUnderflowException +pop ):void +top:Object +isEmpty ) :boolean +StackUnderflowException() +StackUnderflowException (String message) Stack0verflowException BoundedStackInterface UnboundedStackinterface +push (Object element) void+push (Object element):void +StackOverflowException () +StackOverflowException (String message) tisFul1) boolean LinkedStack ArrayStack #top: LLObjectNode #DEFCAP: int stack: Object [] #topIndex: int +Linked Stack() +push (Object element void +pop )void +top ):Object tisEmpty:boolean +ArrayStack() +ArrayStack (int maxsize) +push (Object element) void +pop )void +top ):Object tisEmpty :boolean +isFull) boolean ey -- uses extends implements

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Explain trade credit.

Answered: 1 week ago

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago