[Solved]Introduction Everyday Life Queue Line Helps People Served Order Request Service Example Pe Q37289058
introduction:
In our everyday life, a Queue (or a Line) helps people to be servedin the order they request a service. For example, people form aqueue (line) as they enter the post office. When a person arrives,he or she goes to the “end of the line” (“end of the queue”) andthe person at the “front of the line” (“front of the queue”) is theperson who is served next. For this question, we will use a JavaArrayList of integer numbers to simulate a queuein real life.
To answer this question, please do the following:
1- Copy and paste the following Java code in JGrasp (or the IDEof your choice) and save it as Queue.java
//========= Queue.java Beginning ===============
public class Queue
{
ArrayList q;
public Queue()
{
}
}
//========== Queue.java End ==============
2- Copy and paste the following Java code in JGrasp (or the IDEof your choice) and save it asQueueDemo.java:
//========= QueueDemo.java Beginning===============
public class QueueDemo
{
public static void main(String[] args)
{
Queue q1 = new Queue();
q1.addToEndOfQueue(45);
q1.addToEndOfQueue(15);
q1.addToEndOfQueue(19);
System.out.println (“Queue is empty: ” +q1.isEmpty());
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());
System.out.println (“Queue is empty: ” + q1.isEmpty());
}
}
//========= QueueDemo.java End ===============
Note1: Both files should be saved in the samefolder.
Note2: The QueueDemo.java fileshould not be changed.
The Queue.java class uses anArrayList of integer numbers to simulate a queue.However it is incomplete. Your job is to complete theQueue.java class such that whenyou run theQueueDemo.java, the output that isshown below, at the end of this question, isprinted.
Questions:
1- Implement the following methods inQueue.java
a) public Queue() creates a queue (Theconstructor method).
b) public void addToEndOfQueue(int val) addsthe integer val to the end of the queue.
c) public int getNext() removes the nextinteger from the front of the queue and returns it.
d) public int size() returns the number ofelements (integer numbers) that are currently in thequeue.
e) public boolean isEmpty() returns true if thequeue is empty
2- In order to test yourQueue.java class, runQueueDemo.java and verify that the followingoutput is generated:
Output:
Queue is empty: false
Current Queue size: 3
Next number in the queue: 45
Current Queue size: 2
Next number in the queue: 15
Next number in the queue: 19
Current Queue size: 0
Queue is empty: true
Expert Answer
Answer to introduction: In our everyday life, a Queue (or a Line) helps people to be served in the order they request a service. F… . . .
OR

