Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

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 Node current head; for (inti 0; i temptail; tail current tail.next-null; size-; return temp.element; 137 138 139 140 141 F 142 1436 /** Remove the element at the specified position in this 144 145 public E remove(int index) 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169e @Override Override toString) to return elements in the list 170 public String toString() { if (index - size) I else if (index= 0) { else if (indexsize 1) list. Return the element that was removed from the list. */ return null; return removeFirst); return removeLast); Node previoushead; else for (int i 1; i current -previous.next; previous.next current.next; size return current.element StringBuilder result new StringBuilder("["); 172 173 174 175 176 Node current-head; for (int 1-0; i current head; for (inti 0; i temptail; tail current tail.next-null; size-; return temp.element; 137 138 139 140 141 F 142 1436 /** Remove the element at the specified position in this 144 145 public E remove(int index) 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169e @Override Override toString) to return elements in the list 170 public String toString() { if (index - size) I else if (index= 0) { else if (indexsize 1) list. Return the element that was removed from the list. */ return null; return removeFirst); return removeLast); Node previoushead; else for (int i 1; i current -previous.next; previous.next current.next; size return current.element StringBuilder result new StringBuilder("["); 172 173 174 175 176 Node current-head; for (int 1-0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions