Question: I appreciate any help with the following Java code problem. Please modify the following Java code class queue to include appropriate error messages if invalid

I appreciate any help with the following Java code problem.

Please modify the following Java code "class queue" to include appropriate error messages if invalid conditions occurfor example, trying to dequeue an item when the queue is empty.

/**

* Class implementing a Queue ADT.

*/

public class Queue

{

/**

* Creates an empty queue with an array size of 100.

*/

public Queue()

{

size = 100;

list = new char[size];

front = 0;

back = size - 1;

count = 0;

}

/**

* Creates an empty queue using the array size passed as a parameter.

*

* @param s array size.

*/

public Queue(int s)

{

size = s;

list = new char[size];

front = 0;

back = size - 1;

count = 0;

}

/**

* Adds an element to the back of the queue.

*

* @param c element to be added to the queue.

*/

public void enqueue(char c)

{

back = (back + 1) % size;

list[back] = c;

count++;

}

/**

* Removes the element in the front of the queue.

*/

public void dequeue()

{

front = (front + 1) % size;

count--;

}

/**

* Returns the element at the front of the queue. Does not remove it.

*

* @return the element at the front of the queue.

*/

public char getFront()

{

return list[front];

}

/**

* Determines whether the queue is empty.

*

* @return true if the queue is empty, false otherwise.

*/

public boolean isEmpty()

{

return count == 0;

}

private char[] list; //array to store the queue items

private int size; //size of the array

private int count; //number of items in the queue

private int front, back; //front and back locations

}

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!