QueueArray.java This file implements QueueInterface.java This file has * attributes of an array holding queue elements. An integer represents front * index, an integer for rear index, and an integer to keep track number of * elements in the queue. An overloaded constructor accepts an integer for * initializing the queue size, e.g. array size. An enqueue method receives an * object and place the object into the queue. The enqueue method will throw * exception with message "Overflow" when the queue is full. A dequeue method * returns and removes an object from front of the queue. The dequeue method * will throw exception with message "Underflow" when the queue is empty. A size * method returns number of elements in the queue. A toString method returns a * String showing size and all elements in the queue.
QueueArray.java This file implements QueueInterface.java This file has
* attributes of an array holding queue elements. An integer represents front
* index, an integer for rear index, and an integer to keep track number of
* elements in the queue. An overloaded constructor accepts an integer for
* initializing the queue size, e.g. array size. An enqueue method receives an
* object and place the object into the queue. The enqueue method will throw
* exception with message "Overflow" when the queue is full. A dequeue method
* returns and removes an object from front of the queue. The dequeue method
* will throw exception with message "Underflow" when the queue is empty. A size
* method returns number of elements in the queue. A toString method returns a
* String showing size and all elements in the queue.

![public class QueueDemo {
}
public static void main(String[] args) {
testQueue (new QueueArray<String>(3));
testQueue (new QueueArrayList<String>());
testQueue (new QueueLinkedList<String>());
}
private static void testQueue (Queue Interface<String> q) {
try {
}
q. enqueue ("We're");
q. enqueue ("the");
q.enqueue ("champions.");
System.out.print(q.dequeue()
q.enqueue ("Summer");
System.out.print(q.dequeue()
System.out.println(q.dequeue ());
q. enqueue ("fun.");
System.out.println("\n" + q);
q.dequeue ();
q. dequeue ();
q.dequeue ();
} catch (Exception e) {
}
+ ');
1
+ ');
System.out.println(e.getMessage());
System.out.println(".
.");](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F62544cc1-5b6d-4c69-9690-33e4d8e51c50%2Fae6c4c3b-8969-4679-a5e7-2339711ccc4a%2F73bntx8_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









