
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(".
.");](https://content.bartleby.com/qna-images/question/62544cc1-5b6d-4c69-9690-33e4d8e51c50/ae6c4c3b-8969-4679-a5e7-2339711ccc4a/73bntx8_thumbnail.png)

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- Data Structures/Algorithms in Javaarrow_forward* QueueArrayList.java This file implements QueueInterface.java This file has * only one ArrayList<T> type of attribute to hold queue elements. One default * constructor initializes the ArrayList<T> queue. An enqueue method receives an * object and place the object into the queue. The enqueue method does not throw * overflow exception. A dequeue method returns and removes an object from queue * front. 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. Please help me in javaarrow_forwardJava Given main() in the ShoppingList class, define an insertAtEnd() method in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list. The output is: Kale Lettuce Carrots Peanuts Second image is ItemNodearrow_forward
- determine if the statement is true or false If N represents the number of elements in the queue, then the size method of the ArrayBoundedQueue class is O(N).arrow_forwardb. Write out the order of elements that are contained in a queue after the following operations are performed. myQueue.enqueue(new Integer(16)); myQueue.enqueue(new Integer(12)); Integer num1 = myQueue.dequeue(); myQueue.enqueue(new Integer(6)); myQueue.enqueue(new Integer(8)); myQueue.enqueue(new Integer(30)); myQueue.enqueue(new Integer(24)); myQueue.enqueue(new Integer(18)); myQueue.dequeue(); myQueue.dequeue(); myQueue.dequeue(); myQueue.enqueue(new Integer(38); Show how step by step process of arriving at your answer.arrow_forwardA student record system uses an ArrayList object called studrecs tomaintain a collection of student details where each student is anobject defined by the Student class. The student class has accessormethods getName() and getRegNo()Write a for-each loop that iterates through the studrecs collectionwriting out each student’s name and registration number.arrow_forward
- Change the __str__ method of the Queue class (provided below) so that it prints each object in the queue along with its order in the queue (see sample output below). class Queue(): def __init__(self): self.queue = [] # implement with Python lists! # start of physical Python list == front of a queue # end of physical Python list == back of a queue def enqueue(self, new_obj): self.queue.append(new_obj); def dequeue(self): return self.queue.pop(0) def peek(self): return self.queue[0] def bad_luck(self): return self.queue[-1] def __str__(self): return str(self.queue) # let's try a more fun waySample output: >>> my_queue = Queue()>>> everyone = ["ESC", "ABC", "YOLO", "HTC"]>>> for initials in everyone:>>> my_queue.enqueue(initials)>>> print(my_queue)Output: 1: ESC2: ABC3: YOLO4: HTCarrow_forwardYou will create two programs. The first one will use the data structure Stack and the other program will use the data structure Queue. Keep in mind that you should already know from your video and free textbook that Java uses a LinkedList integration for Queue. Stack Program Create a deck of cards using an array (Array size 15). Each card is an object. So you will have to create a Card class that has a value (1 - 10, Jack, Queen, King, Ace) and suit (clubs, diamonds, heart, spade). You will create a stack and randomly pick a card from the deck to put be pushed onto the stack. You will repeat this 5 times. Then you will take cards off the top of the stack (pop) and reveal the values of the cards in the output. As a challenge, you may have the user guess the value and suit of the card at the bottom of the stack. Queue Program There is a new concert coming to town. This concert is popular and has a long line. The line uses the data structure Queue. The people in the line are objects…arrow_forwardProblem 7: Assume that a queue class called XQueue has a no argument constructor, an enqueue() method, a dequeue() method and an isEmpty() method. Write a method that merges two given queues by copying the elements in an alternating sequence and returning the resulting combined queue. Note: make sure that you don't include unnecessary spaces in your answer! public XQueue merge(XQueue q1, XQueue q2) { XQueue neWQueue = new XQueue(); while (!q1.isEmpty() && !q2.isEmpty()) { newQueue.enqueue( #01 ); newQueue.enqueue( #02); } while (!q1.isEmpty()) { #03 ; } while (!q2.is Empty()) { #04 ; } return newQueue (); }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





