Question: Write two classes and a driver program using a java.util class such as LinkedList that implements the Queue interface with its insert() (enqueue), remove() (dequeue)

Write two classes and a driver program using a java.util class such as LinkedList that implements the Queue interface with its insert() (enqueue), remove() (dequeue) and element()(peek) methods to simulate a line at a bank. The basic idea is to use a "clock" which is simply a loop that counts seconds for simulation, not real seconds, so each time through the loop will simulate one second.

The Customer class

has a one-int-parameter constructor that takes the current clock time as an integer parameter and stores that parameter.

has a public int getWait(int current) method that will return the difference between current and the clock time that was stored from the constructor.

the Teller class

contains a queue of Customer objects

has a constructor with 3 int parameters

the number of seconds to run the simulation

the maximum time before a new customer comes, in seconds

the maximum time to handle one customer's transactions, in seconds

has a public void run()method to run the simulation

Generate a random number less than the second constructor parameter for when the next customer arrives.

Loop while the clock variable is less than the number of seconds to run the simulation.

If the time has elapsed for a new customer to arrive, enqueue a new customer and generate a random number for the next clock time when a customer will arrive.

If the teller is not busy, dequeue a customer, accumulate the number of customers served and the total wait time, and generate a random number to calculate the next clock time when the teller will be free.

increment the clock

has a public void report()method to output, clearly labeled,

the Total time in minutes.

the Average wait time in minutes.

the Number served

If the queue is not empty:

the number of customers still in line

the wait time of the customer in front of the line, in minutes.

The main method should request a total number of seconds, a maximum number of seconds between customers and a maximum processing time in seconds, run the simulation, and print out a report. Try input like 7200, 360 and 240, where the teller can keep up, and like 7200, 240 and 360, where the teller can't keep up.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!