Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Queues This programming exercise introduces the Queue data structure. The studen

ID: 3873884 • Letter: Q

Question

Queues

This programming exercise introduces the Queue data structure. The students must create all the necessary methods for the queue and use the queue in a Java program.

Step 1 - Create a new project in Netbeans

Use the following naming convention: “Module4_Lastname_Assignment1”.

Step 2 - Build a solution

You have been asked to create a customer service program for a new phone store that will be opening soon. Since this company anticipates being the agent for a rising new product that will be able to host the most popular video games–always released at midnight on the eve of the anticipated announcement date–they want a customer service module that will help them manage the customers as they arrive. Customers will be added to the queue as they arrive, removed once they have been served. Sometimes the queue will be search to determine who is there. As a prototype for this system, you are to use the linked list created in Assignment 3.1 to create a queue class and a test program that can handle this new system. The queue class must include a method to insert elements into the queue, remove elements from the queue, look at the first and last element of the queue without removing the elements from the queue, and search for an element in the queue. Use the following algorithm to simulate a simple version of the new system.

Choose a random integer between 1 and 5 to determine the minutes at which a customer arrives.
When a customer arrives, choose a random integer between 1 and 5 to determine the number of minutes that the customer must remain in the checkout line.
Repeat the two steps for a 12 hour (720 minute) simulation.
Run the simulation again with a random integer of 1 and 3 to compare the number of customers in the checkout line against the original 12 hour simulation.
Step 3 - Compile and execute your code

Be sure to test the solution using a set of input data that demonstrates that your solution is correct. Take a screen shot showing the output from your Java program.

Step 4 - Submit your assignment

When you have completed your assignment submit a copy (source code and screen shot) below. Be sure to include your test data.

Explanation / Answer

You can create project in Netbeans naming “Module4_Lastname_Assignment1” and build a solution.

I am providing you solution in C++,if you know JAVA ,you can easily covert the code by simply changing input and output methods. The main logic will remain same in both the case

I will comment each pace in code where there will be some special logic.

#include<iostream>

#include<stdio.h>

#include <unistd.h> //for sleep()

#include<stdlib.h> //for srand() and rand()

using namespace std;

struct node

{

int data;

node *next;

}*front = NULL,*rear = NULL,*p = NULL,*np = NULL;

void push(int x)

{

np = new node;

np->data = x;

np->next = NULL;

if(front == NULL)

{

front = rear = np;

rear->next = NULL;

}

else

{

rear->next = np;

rear = np;

rear->next = NULL;

}

}

void display(){

if(front==NULL){

cout<<"Underflow."<<endl;

return;

}

node *temp=front;

//will check until NULL is not found

while(temp){

cout<<temp->data<<" ";

temp=temp->next;

}

cout<<endl;

}

int remove()

{

int x;

if(front == NULL)

{

cout<<"empty queue ";

}

else

{

p = front;

x = p->data;

front = front->next;

delete(p);

return(x);

  

}

}

int main()

{

int n,c = 0,x;

cout<<"As we are doing simultion for 720 mins ";

srand(time(NULL)); // help in unique random number generation

int cusArrivalTime =rand()%5;

if(cusArrivalTime<1)

cusArrivalTime=1;

int cusWaiTime=rand()%5; //time customer remain in the checkout line

if(cusWaiTime<1)

cusWaiTime=1;

cin>>n;

int totcu=720/cusArrivalTime; //total customer arrived in 720 mins

  

  

while (c < totcu)

{

cout<<"Enter the customerID to be entered into queue ";

cin>>x;

push(x);

sleep(cusArrivalTime); //sleep the insertion till customer arrival time ,it is in sec here

c++;

}

cout<<" Removed Values ";

while(true)

{

if (front != NULL)

{

cout<<remove()<<endl;

sleep(cusWaiTime); //checkout customer from queue after every cusWaitTime determined randomly.

}

else

break;

}

return 0;

}

I think above code will help you in making your project .If you find any difficulty in understanding the code ,you can ask me through comments.