BankSimulation - public void run(int cycles) { int numCust,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************* // BankSimulation.java Author: Lewis/Loftus // // Solution to Programming Project 12.5 // // Simulates customers waiting in line at a bank using a queue // date structure. //******************************************************************* import java.util.Random; public class BankSimulation { private Random gen; private int custCount; private Line line; private final int MAX_NUM_CUSTOMERS = 5; // a slow bank more customers arrive private final int MAX_CUST_SERVICED = 4; // than can be serviced public BankSimulation() { gen = new Random(); custCount = 0; line = new Line(); } //---------------------------------------------------------------- // Runs the simulation for specified number of cycles. After the // cycles are over, the bank closes. //----------------------------------------------------------------
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public void run(int cycles) { int numCust, custServiced; int tellerTime; Customer person; for (int i=0; i<cycles; i++) { numCust = gen.nextInt(MAX_NUM_CUSTOMERS); // customers arriving at bank for (int j=0; j<numCust; j++) { person = new Customer(custCount++); line.addCustomer(person); System.out.println(person + " joins the line"); } custServiced = gen.nextInt(MAX_CUST_SERVICED); // tellers service customers for (int j=0; j<custServiced; j++) { if (line.isEmpty()) System.out.println("Teller waiting"); else { System.out.println(line.nextCustomer() + " is being serviced"); } } } System.out.println("Bank closing . . ."); while (!line.isEmpty()) System.out.println(line.nextCustomer() + " is being serviced"); } public static void main (String args) { new BankSimulation().run(10); } }...
View Full Document

Page1 / 2

BankSimulation - public void run(int cycles) { int numCust,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online