Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 implements Iterable { private Key[] heap; private int size; public Heap(int initCapacity) { heap = (Key[]) new Object[initCapacity + 1]; size = 0; } public Heap() { this(1); } public boolean isEmpty() { return size == 0; } public Key max() { if (isEmpty()) { return null; } return heap[1]; } private void swapKeys(int i, int j) { Key exchange = heap[i]; heap[i] = heap[j]; heap[j] = exchange; } private void resize(int capacity) { assert capacity > size; Key[] temp = (Key[]) new Object[capacity]; for (int i = 1; i <= size; i++) temp[i] = heap[i]; heap = temp; } public void insert(Key x) { if (size >= heap.length - 1) resize(2 * heap.length); heap[++size] = x; swimUp(size); } public Key deleteMaximum()

{ 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) heap[i]).compareTo(heap[j]) < 0; } public Iterator iterator() { return new HeapIterator(); } private class HeapIterator implements Iterator { private Heap dup; public HeapIterator() { dup = new Heap(size());

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 : student submitted image, transcription available below

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 Tick 2 Tick 1 Tick 3 Tick 2 New customer has arrived with the priority 8 and transaction time: 8 Tick 4 Tick 3 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 Tick 6 New customer has arrived with the priority 6 and transaction time: 6 Tick 7 Tick 6 kkkkkkkkkkkkkkkkkkkkkkkkkk New customer has arrived with the priority 10 and transaction time: 16 1 customers waiting right now! Tick 442 Tick 8 Tick 443 Custoner Leaves, customer waited for 47 units of time. Tick 1283 Tick 444 Tick 1284 Tick 1284 Customer Leaves, customer waited for 4 units of time. Tick 1285 Custoner's serviced: 200. . Average waiting time: 27.44 Tick 445 Tick 1286 Customer Leaves, customer waited for 881 units of time

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

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions

Question

Demonstrate three aspects of assessing group performance?

Answered: 1 week ago