Question: To answer this question, please copy the Queue.java and QueueDemo.java classes provided below and paste them in separate files with the same names: //----------------------------------------------- //

To answer this question, please copy the Queue.java and QueueDemo.java classes provided below and paste them in separate files with the same names:

//----------------------------------------------- // Queue.java //----------------------------------------------- import java.util.ArrayList; public class Queue { ArrayList al; public Queue() { } public void addToEndOfQueue(int val) { } public int getNext() { } public int size() { } }

//----------------------------------------------- // QueueDemo.java //----------------------------------------------- public class QueueDemo { public static void main(String[] args) { Queue q1 = new Queue(); q1.addToEndOfQueue(10); q1.addToEndOfQueue(5); q1.addToEndOfQueue(18); System.out.println ("Current Queue size: " + q1.size()); System.out.println ("Next number in the queue: " + q1.getNext()); System.out.println ("Current Queue size: " + q1.size()); int qSize = q1.size(); for (int i = 0; i< qSize;i++) { System.out.println ("Next number in the queue: " + q1.getNext()); } System.out.println ("Current Queue size: " + q1.size()); } }

Your job is to complete the Queue class in Queue.java such that when the QueueDemo.java is run, an output that is shown at the end of this question below is printed. Please submit your completed Queue.java file on the blackboard and/or email it to me. (Please note that the QueueDemo.java file should not be changed.)

Introduction: A Queue (or line) helps people to be served in the order they request a service; For example, people form a Queue (line) as they enter the post office. When a person arrives, he or she goes to the End of the Queue (line) and the person at the Front of the Queue (line) is the person who is served next. Question: The Queue.java class simulates a queue of integer numbers. A new integer is added to the end of the queue using the addToEndOfQueue(int val) method. The getNext() method returns the next integer in front of the queue. The size() method returns the number of integers currently in the queue. 1- Complete the following methods in Queue.java: a) public Queue() creates a queue (The constructor method). b) public void addToEndOfQueue(int val) adds the integer val to the end of the queue. c) public int getNext() removes the next integer from the front of the queue and returns it. d) public int size() returns the number of elements (integer numbers) that are currently in the queue. 2- Run QueueDemo.java and verify that the following output is generated: Current Queue size: 3 Next number in the queue: 10 Current Queue size: 2 Next number in the queue: 5 Next number in the queue: 18 Current Queue size: 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!