Problem

Implement the shopping cart simulation described in Section 17.2 so that it runs for a spe...

Implement the shopping cart simulation described in Section 17.2 so that it runs for a specified number of minutes. A counter can be used to keep track of the current minute in the simulation. Each time the counter advances, the simulation code handles all of the actions to be performed during that minute. You can use a stack to represent the column of waiting carts, and a priority queue to represent the active carts.

Each Cart object should keep track of the total time it has been active. Use the random-number generator to determine how many minutes (1 to 60) that a cart will be active when it is taken out, and how many customers take carts out in each minute. Keep in mind that the priority queue pops the element with the greatest value, so you will want the Cart object’s

At the start of every minute, check the front of the priority queue to see if the front cart’s return time is the same as the current minute, and move it back to the stack. Be sure to check for more than one cart being returned in a given minute. Then determine the number of carts to be taken out during that minute and their activity times, and push them into the priority queue. Remember to watch out for empty container situations. At the end of the simulation, any carts that remain active should be transferred back to the stack. Then, for each cart, output its ID number and total activity time.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
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