Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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) { ArrayCircularQq = 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started