Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete where says //to complete import java.util.ArrayList; import java.util.NoSuchElementException; /** * A class of queue whose entries are stored in a dynamic array public class

Complete where says //to complete

import java.util.ArrayList;
import java.util.NoSuchElementException;

/**
* A class of queue whose entries are stored in a dynamic array

public class ArrayDynamicQueue implements QueueInterface
{
/*==============================================================================
INSTANCE VARIABLES
==============================================================================
*/
//An array of queue entries
private ArrayList queue;

//Index of front entry and rear entry
private int front, rear;

/*==============================================================================
CONSTRUCTORS
==============================================================================
*/
/**
* A default constructor for this queue
*/
public ArrayDynamicQueue()
{ //to-complete
}

/**
* Create a queue with a specific initail capacity
* @param initCapacity the initial capacity of this queue
*/
public ArrayDynamicQueue(int initCapacity)
{ //to-complete
}

/* =============================================================================
INSTANCE METHODS
=============================================================================
*/
/* ---------------------- Getters --------------------------------------------*/
/**
* Get a full queue
* @return a full queue
*/
public ArrayList getQueue()
{ //to-complete
}

/**
* Get the index of front entry
* @return the index of front entry
*/
public int getFrontPos()
{ //to-complete
}

/**
* Get the index of rear entry
* @return int getRearPos()
*/
public int getRearPos()
{ //to-complete
}

/* -------------------- Setters ---------------------------------------------*/
/**
* To set this queue to a new queue
* @param queue a new queue
*/
public void setQueue(ArrayList queue)
{ //to-complete
}
/* ------------------- Other methods -----------------------------------------*/

/**
* Detects whether this queue is empty
* @return True if the queue is empty, or false otherwise
*/
public boolean isEmpty()
{ //to-complete
}

/**
* Count the number of entries in this queue
* @return the number of entries in this queue
*/
public int size()
{ //to-complete
}

/**
* Retrieve the entry at the font of this queue
* @return The object at the front of the queue
* @throws NoSuchElementException if the queue is empty before the operation
*/
public T getFront()
{ if (isEmpty())
throw new NoSuchElementException("Queue is empty, no front element");
else
//to-complete
}

/**
* Remove and returns the entry at the front of this queue
* @return The object at the front of the queue
* @throws NoSuchElementException if the queue is empty before the operation
*/
public T dequeue()
{ if (isEmpty())
throw new NoSuchElementException("Queue is empty, cannot remove");
else
//to-complete
}

/**
* Adds a new entry to the back of this queue
* @param newEntry An object to be added
*/
public void enqueue(T newEntry)
{ //to-complete
}

/**
* Removes all entries from this queue
* @throws NoSuchElementException if the queue is empty before the operation
*/
public void clear()
{ if (isEmpty())
throw new NoSuchElementException("Cannot clear an empty queue");
else
//to-complete
}

/**
* List out all entries in this queue
*/
public void display()
{ //to-complete
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

youve provided a Java class named ArrayDynamicQueue which implements the QueueInterface This class handles a queue with entries stored in a dynamic ar... 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

Data Structures and Algorithms in Python

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

1st edition

1118290275, 1-118-54958-2, 978-1118290279

More Books

Students also viewed these Operating System questions

Question

What do we know about police officers as eyewitnesses?

Answered: 1 week ago

Question

What do we know about elderly people as eyewitnesses?

Answered: 1 week ago