Question
For this assignment, you will write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of
For this assignment, you will 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 instead include a single add method that adds the item in the correct (sorted) spot, smallest items at the head. Use this method header: public void add(E e) Indicates that the generic item will have implemented the Comparable interface by specifying the class in this way: public class MySortedList>
Queue: Implement a generic queue with an ArrayList as the only instance variable. The constructor will instantiate the list. Include standard enqueue and dequeue methods, as well as isEmpty, getSize, and to String.
Customer: The following information should be included as private variables in the Customer class: customerNumber, storeArrivalTime, and shoppingLength. All variables are of type int. There will be NO mutator (setter) methods. Be sure your class meets these requirements: The constructor should do the following: Set the customerNumber (use a static class variable for this) Set storeArrivalTime (use the simClock, which will be a parameter to the constructor) Set shoppingLength (a random number between 5 and 45) There should be accessor (getter) methods for the following: customerNumber storeArrivalTime shoppingLength checkoutArrivalTime (storeArrivalTime + shoppingLength) checkoutLength (the integer ceiling of shoppingLength/5). Include a toString method that displays all information for the customer Implement the Comparable interface with compareTo based on checkOutArrivalTime.
Cashier: extends your Queue class and includes a finishTime instance variable of type integer. finishTime will be set to 0 in the constructor. Include an accessor for finishTime as well as these methods: public boolean addcustomer(Customer c) //call enqueue public Customer serveNextcustomer (int simClock) //if the queue is empty, returns null. Otherwise, dequeues an item, sets the finish time equal to (simulation clock + customers checkoutLength) and returns the customer.
Data objects needed in the driver program: A CustomerList a sortedList of customers representing the customers currently shopping An array of Cashiers (checkout lanes)
Output files needed: You will need two output files: one to store the summary information and one to store details of the simulation.
Other: A simulation clock (an integer variable) Declare other variables as needed to store the necessary counters and statistics, and to manage the simulation.
Simulation procedure: 1. Declare data objects, files, etc. 2. Get input: Number of open checkout lanes (integer, user must enter a number >= 1) Length (in minutes) of the simulation (int, user must enter a number >= 10) Number of customers expected to enter the store during each hour (integer between 1 and 60) 3. Initialize variables (create the appropriately-sized array of cashiers; set simulation clock to 0, number of customers to 0, etc.) 4. Begin simulation loop (a counted loop that increments the simClock each iteration until simulation length is reached; start the counter at 1): If a new customer has arrived to the store (determined by a random function described below): Create a new customer (use the simClock as storeArrivalTime) Increment the number of customers created. Add customer to customer list If customers are ready to check out (when their checkOutArrivalTime == simulation clock) Remove the customer from the customer list and add the customer to cashier with shortest checkout line. Keep in mind more than one customer could be ready to check out during each clock cycle. Update cashiers. For each cashier: If the cashiers finishTime
5. After the simulation loop, output all input values to the summary output file. (number of checkout lanes used, length of the simulation, number of customers expected to enter the store during each hour)
6. After the simulation loop, output all simulation statistics to the summary output file: Number of customers who entered the store during the simulation Number of customers still shopping (not in line) Number of customers waiting in a checkout line but not yet being served Number of customers who have been or are currently being served by cashiers Average wait time for all customers who have been or are currently being served (rounded to two places to the right of the decimal)
7. Write a message to the console indicating that the simulation is finished, and where the simulation information can be found (state the file names for the details and summary information). Calculation of whether new customer has arrived (needed for step 4 above): To write the method for determining if a customer has arrived, first calculate the arrivalProbability for a new customer in any given minute of the simulation (assume each clock tick represents a minute). This can be calculated using the information input from the user regarding length of simulation in hours and number of customers arriving per hour. Once you have the probability per minute, use it as follows: Calculate the arrival probability per hour (expected # of customers per hour / 60 * 100). This needs to be of type double Generate a random integer between 0 and 100 If the number is less than or equal to the arrivalProbability, assume a new customer has arrived. If the number is greater than the arrivalProbability, no customer has arrived. Generating random integers between two boundaries, inclusive: randomNum = (int) (lowerBound + Math.random() * (upperBound lowerBound + 1));
Before writing the simulation portin of this project, it is important that the classes that will be used have been thoroughly tested. I suggest you do this preliminary work, writing driver programs as indicated. These driver programs are for testing only, and should not be part of your finishsed project. 1. Create queue class and thoroughly test all methods with a separate driver program 2. Create sorted list class and thoroughly test all methods with a separate driver program 3. Create the Cashier class and write a driver to thoroughly test all methods. 4. Create the Customer class and write a driver to thoroughly test all methods. When you come in for help on this project, your instructor or TA may ask to see your test programs, to verify that your classes work correctly. Additionally, you may want to create a driver program that creates an array of cashiers and a sorted list of Customers. Verify that you are able to add and remove items to both the array and the list.
else 128 129 130 131 132 133 134 135 NodeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started