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

Java Grocery Store Queue Simulation Write a program that simulates customers wai

ID: 3557940 • Letter: J

Question

Java Grocery Store Queue Simulation

Write a program that simulates customers waiting in line at a grocery store. Your program must use a Queue to represent the customer objects waiting in line.
A Customer class is provided below to be used with this program. You must use that class, without alterations, for the creation of your Customer objects. You must analyze the class and use the provided methods to achieve the desired functionality of the program.
The program should simulate 60 minutes of activity at the store. Each iteration of your program should represent one minute. At each iteration (minute), your program should do the following:

Explanation / Answer

import java.util.*; public class GrocerySim { private Queue checkLine; private ArrayList customers; private int numCustomers; private Customer currCust; private CheckOut cashier; private Random r; public GrocerySim(int n) { FEL = new PriorityQueue(); // Keeping the Future Event List as a PQ allows // it to be maintained by the next closest event // (or smallest into the future). checkLine = new LinkedList(); // The customers waiting to be // checked out are in a simple queue (FIFO). numCustomers = n; customers = new ArrayList(); cashier = new CheckOut(); r = new Random((new Date()).getTime()); // Seed the random number // generator so output differs from run to run. } // Iterate as long as there are events left in the FEL. Since events are // both arrival events and completion events, we must distinguish between // the two and take different actions accordingly. See classes SimEvent, // ArrivalEvent and CompletionEvent for details on how they are set up. public void runSimulation() throws ClassNotFoundException { int custNum = 0; int clock = 0; FEL.add(new ArrivalEvent(0)); // Initialize FEL with first arrival // Simulation should run until no more events are left while (!FEL.isEmpty()) { SimEvent e = FEL.remove(); clock = e.get_e_time(); if (Class.forName("ArrivalEvent").isInstance(e)) { custNum++; currCust = new Customer(custNum, e.get_e_time()); currCust.serviceT = serviceTime(); if (!cashier.isBusy()) { currCust.startServiceT = clock; cashier.addCust(currCust); FEL.add(new CompletionEvent(clock + currCust.serviceT)); } else { checkLine.add(currCust); } if (custNum
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote