n this assignment, you should provide a complete CircularQueueDriver class that fully tests the functionality of your CircularQueue class that you have improved in Lab 8. Your CircularQueueDriver class should: • Instantiate a 3-element CircularQueue. • Use a loop to add strings to the queue until the add method returns false (which indicates a full queue). • Call showQueue. • Use a loop to remove strings from the queue until the remove method returns null (which indicates an empty queue). As you remove each string from the queue, print the removed string. Sample Run: Monsieur A Monsieur B Monsieur C removed: Monsieur A removed: Monsieur B removed: Monsieur C CircularQueue Class: public class CircularQueue {     private String[] queue; // array that implements a circular queue     private int length = 0; // number of filled elements     private int capacity; // size of array     private int front = 0; // index of first item in queue     private int rear = 0; // one past the index of the last item     // Instantiate the queue's array with the given capacity.     public CircularQueue(int capacity) {         queue = new String[capacity];         this.capacity = capacity;     }     public boolean isEmpty() {         return length == 0;     }     public boolean isFull() {         return length == capacity;     }     public int length() {         return length;     }     // Add a value to the rear of the queue by using the rear's     // current position and then incrementing rear.     public boolean add(String name) {         if (isFull()) {             return false;         }         queue[rear] = name;         rear = (rear + 1) % capacity; // if rear gets too big, assign it to 0         length++;         return true;     }     // Remove the value at the front of the queue and then increment     // front.     public String remove() {         if (isEmpty()) {             return null;         }         String result = queue[front];         queue[front] = null;         front = (front + 1) % capacity;         length--;         return result;     }     // Display the queue's contents in front-to-rear order.     public void showQueue() {         if (isEmpty()) {             return;         }         for (int i = front; i != rear; i = (i + 1) % capacity) {             System.out.println(queue[i]);         }     }          public static void main(String[] args) {         CircularQueue queue = new CircularQueue(5);         queue.add("Alice");         queue.add("Bob");         queue.add("Charlie");         queue.showQueue();         queue.remove();         queue.showQueue();     }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In Java

In this assignment, you should provide a complete CircularQueueDriver class that fully
tests the functionality of your CircularQueue class that you have improved in Lab 8. Your
CircularQueueDriver class should:
• Instantiate a 3-element CircularQueue.
• Use a loop to add strings to the queue until the add method returns false (which
indicates a full queue).
• Call showQueue.
• Use a loop to remove strings from the queue until the remove method returns null
(which indicates an empty queue). As you remove each string from the queue, print the
removed string.
Sample Run:
Monsieur A
Monsieur B
Monsieur C
removed: Monsieur A
removed: Monsieur B
removed: Monsieur C

CircularQueue Class:

public class CircularQueue {
    private String[] queue; // array that implements a circular queue
    private int length = 0; // number of filled elements
    private int capacity; // size of array
    private int front = 0; // index of first item in queue
    private int rear = 0; // one past the index of the last item

    // Instantiate the queue's array with the given capacity.
    public CircularQueue(int capacity) {
        queue = new String[capacity];
        this.capacity = capacity;
    }

    public boolean isEmpty() {
        return length == 0;
    }

    public boolean isFull() {
        return length == capacity;
    }

    public int length() {
        return length;
    }

    // Add a value to the rear of the queue by using the rear's
    // current position and then incrementing rear.
    public boolean add(String name) {
        if (isFull()) {
            return false;
        }
        queue[rear] = name;
        rear = (rear + 1) % capacity; // if rear gets too big, assign it to 0
        length++;
        return true;
    }

    // Remove the value at the front of the queue and then increment
    // front.
    public String remove() {
        if (isEmpty()) {
            return null;
        }
        String result = queue[front];
        queue[front] = null;
        front = (front + 1) % capacity;
        length--;
        return result;
    }

    // Display the queue's contents in front-to-rear order.
    public void showQueue() {
        if (isEmpty()) {
            return;
        }
        for (int i = front; i != rear; i = (i + 1) % capacity) {
            System.out.println(queue[i]);
        }
    }
    
    public static void main(String[] args) {
        CircularQueue queue = new CircularQueue(5);
        queue.add("Alice");
        queue.add("Bob");
        queue.add("Charlie");
        queue.showQueue();
        queue.remove();
        queue.showQueue();
    }
}

Expert Solution
steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Map
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education