Question: The StringQueue Class: Design a class named StringQueue for storing strings of first names into a queue. The StringQueue.java class contains: * A String[] data

The StringQueue Class:

Design a class named StringQueue for storing strings of first names into a queue. The StringQueue.java class contains:

* A String[] data field named names that stores the String values in the queue.

* A private data field named size that stores the number of names in the queue.

* A public static final data field named DEFAULT_CAPACITY = 10 for the array.

* A private static data field named firstInitCtr that counts the number of names with the same first initial as your first initial.

* A StringQueue no-arg constructor that uses this(DEFAULT_CAPACITY) to construct an object with the default capacity for the string array.

* A StringQueue constructor that receives a new capacity to construct an object with the new capacity for the queue. The new capacity cannot be larger than the default capacity, and cannot be less than 1.

* The method enqueue(String value) that adds value into the queue.

* The method dequeue() that returns the first name from the queue and then shifts the remaining names in the queue to the left.

* The method empty() that returns true if the queue is empty.

* The method getSize() that returns the size of the queue.

* The method checkFirstInit(char firstInit) that adds 1 to the firstInitCtr if the name begins with your first initial.

* The method getFirstInitCtr() that returns the number of names with the same first initial as your name in the queue.

Write a test program called TestStringQueue.java that gets Scanner input for your first name, the number of first names in your queue (indicate the maximum is 10), and then ask for the names to populate the queue using the enqueue method. Invoke the checkFirstInit method to see if the first initial is the same as your first initial, and if so, increment the firstInitCtr. The first initial can either be in upper or lower case for it to be equal. Then, print out the names using the dequeue method. Finally, print out the number of names that begin with your first initial.

Sample runs:

Please enter your first name: joe

Please enter the number of names in your array. Maximum is 10: 11

Please enter the number of names in your array. Maximum is 10: 0

Please enter the number of names in your array. Maximum is 10: 5

Please enter 5 names for the queue: jim John ben carol Joe

Names dequeued:

jim John ben carol Joe

The number of names with your first initial is 3

Please enter your first name: Dan

Please enter the number of names in your array. Maximum is 10: 3

Please enter 3 names for the queue: sam dave ed

Names dequeued:

sam dave ed

The number of names with your first initial is 1

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!