Question

Queues This programming exercise introduces the Queue data structure. The students must create all the necessary...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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\n";

}

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\n";

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\n";

cin>>x;

push(x);

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

c++;

}

cout<<"\n\nRemoved Values\n\n";

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.

Add a comment
Know the answer?
Add Answer to:
Queues This programming exercise introduces the Queue data structure. The students must create all the necessary...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • USE JAVA PROGRAMMING LANGUAGE See all photos + Add to a ♡ Search Edit & Create...

    USE JAVA PROGRAMMING LANGUAGE See all photos + Add to a ♡ Search Edit & Create Share . Benny the Barber owns a one-chair shop. They told Benny that customers are not happy with waiting in lines and not get processed in order they arrived. As computer scientist, you are going to help Benny to write a Java program to manage waiting lines and to process customers in the same order they arrive. Here are the functional requirements of the...

  • C++ Sample run might look like this: How many minutes should the simulation run? 10 Running...

    C++ Sample run might look like this: How many minutes should the simulation run? 10 Running simulation for 10 minutes. minute 1: nothing happens minute 2: customer 1 arrives and will need 3 minutes to check out minute 3: nothing happens minute 4: customer 2 arrives and will need 1 minute to check out minute 5: customer 3 arrives and will need 1 minute to check out minute 5: customer 1 has checked out minute 6: customer 2 has checked...

  • This is Python programming to develop a multithread program. Please follow the step below. 1. You...

    This is Python programming to develop a multithread program. Please follow the step below. 1. You need to develop a multithread program in Python to simulate a checkout in supermarket. The process of simulation will last for T1 seconds. You do not need to consider thread safety. 2. An integer sequence t is used to record the remaining waiting time for each customer. 3. One thread which runs every one second is used to simulate the processing of the checkout....

  • Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I...

    Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I have so far just basically adds customers to the queue and prints when they arrive. I am struggling with how to implement a way of keeping track of when a given customer finishes(I will attach what I have so far). I had already created queue and node classes (with headers and cpp files) that I modified in my attempt. I would be very grateful...

  • PLEASE DO NOT COPY CODE FROM OTHER QUESTIONS POSTED WITH THIS. THAT IS C++ NOT PYTHON...

    PLEASE DO NOT COPY CODE FROM OTHER QUESTIONS POSTED WITH THIS. THAT IS C++ NOT PYTHON Please follow the step below. 1. You need to develop a multithread program in PYTHON to simulate a checkout in supermarket. The process of simulation will last for T1 seconds. You do not need to consider thread safety. 2. An integer sequence t is used to record the remaining waiting time for each customer. 3. One thread which runs every one second is used...

  • C++ -- Event processing simulation using a transaction queue Hi! it is queue simulation please read...

    C++ -- Event processing simulation using a transaction queue Hi! it is queue simulation please read the instructions, write codes, and explain the code with comments. Thank you Transactions enter the system and are stored in a queue. Each transaction represents some work that needs to be accomplished. Servers exist which process transactions. Servers take transactions off the queue and process them. you’re building the simulation framework. The idea is that somebody would take your framework, and add the specifics...

  • Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code...

    Hi! it is c++ queue simulation please read the instructions, write codes, and explain the code with comments. Thank you Transactions enter the system and are stored in a queue. Each transaction represents some work that needs to be accomplished. Servers exist which process transactions. Servers take transactions off the queue and process them. you’re building the simulation framework. The idea is that somebody would take your framework, and add the specifics for whatever type of system it was going...

  • Objective: To implement the programming languages features discussed in class and to develop a program that...

    Objective: To implement the programming languages features discussed in class and to develop a program that uses Graphical User Interfaces (GUI) that provides a friendly environment for users. Project Assignment Design and implement a Hotel Reservation System. The hotel has two types of rooms. One is regular room that has two beds. Another is deluxe room that has two beds and a safe. The regular room price is $120 per night. The deluxe room is $130 per night. A safe...

  • Overview For this assignment, we will practice using stacks and queues. In this exercise, you will...

    Overview For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem. Specifications Rules FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT