Question
DO NOT COPY OTHER CODES FROM CHEGG. THEY DO NOT WORK. I WILL DOWNVOTE IF YOU COPY/PASTE In JAVA, PROVIDED HEAP CLASS MUST BE USED.
DO NOT COPY OTHER CODES FROM CHEGG. THEY DO NOT WORK. I WILL DOWNVOTE IF YOU COPY/PASTE In JAVA, PROVIDED HEAP CLASS MUST BE USED.
The simulation process involves handling events, where the number of tellers needed for efficient service is determined by inputting the initial number of tellers before the start of the simulation. The aim is to determine the average wait time for customers in line and this information will be used by bank officers to ensure smooth customer service. Use a Max-Heap as the underlying data structure for the customer queue. Heap.java is provided for you on Canvas. Define a class Customer which has the fields processTime and priority. In order to compare Customer objects, you need to override the compareTo method in the Customer class. Build a class Simulation, which coordinates each arrival and each departure. The timer should be used to automatically advance your simulation.
Example Timer code: import javax.swing.Timer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class timeSimExample { static int counter = 0; public static void main(String[] args) { Timer timer = new Timer(100, new TimerListener()); timer.start(); while(true){ } } private static class TimerListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { System.out.println("Tick "+counter); counter++; methodCall(); } private void methodCall() { System.out.println("here"); } } }
Heaper.java class that must be used:
import java.util.Iterator; public class Heap
{ if (isEmpty()) { return null; } Key max = heap[1]; swapKeys(1, size--); sinkDown(1); heap[size+1] = null; if ((size > 0) && (size == (heap.length - 1) / 4)) resize(heap.length / 2); return max; } private void swimUp(int i) { while (i > 1 && isLess(i/2, i)) { swapKeys(i, i/2); i = i/2; } } public int size() { return size; } private void sinkDown(int i) { while (2*i <= size) { int j = 2*i; if (j < size && isLess(j, j+1)) j++; if (!isLess(i, j)) break; swapKeys(i, j); i = j; } } private boolean isLess(int i, int j) { return ((Comparable
for (int i = 1; i <= size; i++) dup.insert(heap[i]); } public boolean hasNext() { return !dup.isEmpty(); } public void remove() { throw new UnsupportedOperationException(); } public Key next() { if (!hasNext()) { return null; } return dup.deleteMaximum(); } }} Implementation The simulation should be driven by a ticking time. A tick is a quantum unit set by the simulation, say 1000 milliseconds. The vents are generated by the passage of time (ticks). Event parameters should be generated according to a random variable. At any point, the next event that can occur is either the next customer arrives, with a given priority and a given transaction time, or one of the customers at a teller leaves. Note, several events may occur during the same tick. Namely, a customer arrives and one or more of the customers at a teller leave. If the event is an arrival, a customer is created with an initial priority and a need to spend a certain number of ticks at the teller to complete his/her transaction (processTime). o Both the initial priority and the length of transaction time are assigned randomly at the time of customer generation. o The priority should be generated in the range of 1-10. o The transaction time should be generated in the range of 5-20. o Add that customer to a heap priority queue based on the customer's assigned priority. After each new arrival, increment the priorities of the already existent customers by a constant value, say one. If the event is a departure, processing includes gathering statistics for the departing customer (specifically, waiting time). Print out each tick and any events that occur during that tick. If a customer leaves, print the current average waiting time for customers. OUTPUT I WANT :
Sample output for two different runs. Simulation on the left has 2 bank tellers, the simulation on the right has 6 bank tellers. New customers are not admitted if the total number of waiting customers combined with the total being processed is greater than 200. Welcome to the Bank Simulation! Welcome to the Bank Simulation! Please enter a number of Tellers: Please enter a number of Tellers: 2 6 Tick Tick Tick 1 New customer has arrived with the priority 3 and transaction time: 9 Tick 2 Tick 1 kkkkkkkkkkkkkkkkkkkkkkkk Tick 3 Tick 2 New customer has arrived with the priority 8 and transaction time: 8 Tick 3 Tick 4 Tick 4 New customer has arrived with the priority 4 New customer has arrived with the priority 2 and transaction time: 13 and transaction time: 5 Tick 5 Tick 5 Tck 6 New customer has arrived with the priority 6 and transaction time: 6 Tick 7 Tick 6 New custoner has arpived with the priority 10 and transaction time: 16 1 customers waiting right now! Tiek 442 Tick 8 Tick 443 Tick 1283 Customer"s serviced: 199. . Average waiting time: 27.25 Tick 444 tirkitk kk+k Tick 1284 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk TICK 1284 Customer Leaves, customer waited for 40 units of time. Customer"s serviced: 200. . Average waiting time: 27.44 Tick 1285 Tick 445 Tick 1286 Customer Leaves, customer waited for 881 units of time. Customer's serviced: 200. Averade waiting time: 834.15Step 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