Question: For Java Implement a circular queue using an array. Please name your class ArrayCircularQ.java . Make sure you use the existing QInterface interface. You may

For Java

Implement a circular queue using an array. Please name your class ArrayCircularQ.java. Make sure you use the existing QInterface interface. You may use the attached test program to test your ArrayCircularQ class.

QInterface.java

public interface QInterface { public void insert(T newEntry); public boolean isFull(); public boolean isEmpty(); public T remove(); public T peek(); public void clear(); public void printQ(); } 

TestArrayCircularQ.java

import java.util.Scanner;

 public class TestArrayCircularQ { public static void main(String [] args) { ArrayCircularQ q = new ArrayCircularQ(5); Scanner input = new Scanner(System.in); int option = 0; String item = ""; do { System.out.println("0. Exit"); System.out.println("1. Insert into queue"); System.out.println("2. Remove from queue"); System.out.println("3. Check if queue is empty"); System.out.println("4. Check if queue is full"); System.out.println("5. Peek the front of the queue"); System.out.println("6. Clear the queue"); System.out.println("Enter a choice: "); option = input.nextInt(); switch (option) { case 1: // insert System.out.print("Enter a string: "); item = input.next(); q.insert(item); q.printQ(); break; case 2: // remove item = q.remove(); System.out.println(item + " removed."); q.printQ(); break; case 3: // isEmpty if (q.isEmpty()) System.out.println("Queue is empty."); else System.out.println("Queue is not empty."); break; case 4: // isFull if (q.isFull()) System.out.println("Queue is full."); else System.out.println("Queue is not full."); break; case 5: // peek item = q.peek(); System.out.println("The first item is: " + item); q.printQ(); break; case 6: // clear q.clear(); break; } } while (option != 0); } } 

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!