Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to make a bank simulation where a user enters the number of tellers they want and then for every tick there's a chance

I need to make a bank simulation where a user enters the number of tellers they want and then for every tick there's a chance that a customer object will be created with a process time and priority time. Customers who have a higher priority time should be helped first when the next teller is available, and the process time determines how many ticks the customer will spend at the teller before the teller can help the next customer. The customers are stored in a MaxHeap. Below is a portion of my output. My terminal is not printing when the customer leaves and so I am not even sure if the customer is being stored in the heap. Tick 10 *************** Tick 11 New customer has arrived with the priority 4 and transaction time: 8 Below is the output I want. image text in transcribed 
HEAP CLASS package lab4; 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 = 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 ) heap[i]).compareTo(heap[j])  iterator() { return new HeapIterator(); } private class HeapIterator implements Iterator { private Heap dup; public HeapIterator() { dup = new Heap(size()); for (int i = 1; i  

DRIVER

package lab4; import javax.swing.Timer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; public class Simulation { static int counter = 0; static Heap customerList = new Heap(); static Random random = new Random(); static int customerServed = 0; static int tellerCount; public static void main(String[] args) { //gather bank teller amount from user System.out.println("Welcome to the Bank Simulation!"); System.out.println("Please enter the number of Tellers:"); Scanner scan = new Scanner(System.in); int tellerCount = scan.nextInt(); System.out.println(); //start simulation Timer timer = new Timer(1, new TimerListener()); timer.start(); while (true){ } } public static class TimerListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { //tick processes System.out.println("Tick "+ counter); addCustomer(); while (tellerCount > 0 && !customerList.isEmpty()){ serveCustomer(); tellerCount--; } //increment wait and priority for customers in heap Iterator itr = customerList.iterator(); while (itr.hasNext()){ Customer temp = itr.next(); temp.incrementPriority(); temp.incrementWaitTime(); } System.out.println("***************"); counter++; //closing processes if (counter > 200 || customerList.size() > 200){ if (customerList.size() > 200 && counter   Welcome to the Bank Sinulation! 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 kkkkkkkkkkk and transaction time: 9 Tick 2 Tick 1 Tick 3 Tick 2 New customer has arrived with the priority 8 and transaction time: 8 Tick 4 Tick 3 New customer has arrived with the priority 4 and transaction time: 13 Tick 4 Tick 5 New customer has arrived with the priority 2 and transaction time: 5  Tick 5 Tick 6  New customer has arrived with the priority 6 Tick 7 Tick 6 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk New customer has arrived with the priority 10 and transaction time: 16 1 customers waiting right now! Tick 442 Tilck 8 Tick 443 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk Customer Leaves, customer waited for 47 units of time. Tick 1283 Tick 444 Tick 1284 Customer Leaves, customer waited for 4 units of time. *ick 1285 Customer's serviced: 200...Average waiting time: 27.44 Tick 445 Tick 1286 ************************************ Customer Leaves, customer waited for 881 units of time. Customer's serviced: 200.. Average waiting time: 834.15 Tick 1287

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 Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago