Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is a portion of my code. I am having an issue where the customer isn't showing as leaving more than once. Please help. package

Below is a portion of my code. I am having an issue where the customer isn't showing as leaving more than once. Please help. package lab4; import javax.swing.Timer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; public class BankSimulation { static int totalWaitTime = 0; static int totalCustomers = 0; static int tellerCount = 0; static Heap customerList = new Heap<>(); static Queue wait = new LinkedList<>(); public static void main(String[] args) { /* Scanner scan = new Scanner(System.in); System.out.println("Welcome to the Bank Simulation!"); System.out.print("Please enter the number of Tellers: "); //gather user input tellerCount = scan.nextInt(); //append tellers to array */ //initiate simulation Timer timer = new Timer(100, new TimerListener()); timer.start(); while(true){ } } private static class TimerListener implements ActionListener { int counter = 1; int processTime; int priority; int tellerCount = 6; @Override public void actionPerformed(ActionEvent e) { System.out.println("Tick " + counter); //ADD if (Math.random() < 0.5) { Random random = new Random(); priority = random.nextInt(10) + 1; processTime = random.nextInt(16) + 5; Customer customer = new Customer(processTime, priority, counter); customerList.insert(customer); System.out.println("New customer has arrived with the priority " + priority + " and transaction time: " + processTime); } //PROCESS Customer temp = wait.peek(); if (temp != null) { if (temp.getDeparture() == counter) { System.out.println("Customer Leaves, customer waited for"); wait.remove(); tellerCount++; } } if (!customerList.isEmpty()){ if (tellerCount > 0){ tellerCount--; Customer max = customerList.max(); wait.add(max); customerList.deleteMaximum(); } } Iterator itr = customerList.iterator(); while (itr.hasNext()){ Customer update = itr.next(); update.incrementPriority(); } counter++; } }

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions