Question
A cashier is responsible for helping a queue of customer. It serves one customer at a time. Since the simulation is used to produce statistics,
A cashier is responsible for helping a queue of customer. It serves one customer at a time. Since the simulation is used to produce statistics, a cashier also memorizes the total number of customer served, the total amount of time the customers have been waiting, as well as the total number of items served (processed). Make sure you identified instance variables and class variables.
• The class has a tingle constructor. It has no parameters. It initializes the instance variables of the cashier.
• The method add Customer (Customer c) adds a customer to the rear of its queue. The method int getQueueSize() returns the number of customers currently waiting in line.
• The method serveCustomers( int currentTime ) is a key element of the simulation. The method serveCustomers of eadi cashier is called once for each step of the simulation. The parameter cur-rentTime is used to commute the total amount of time this customer has spent waiting in line. Here is the behaviour of the cashier when serving customers.
— If the cashier is not presently serving a customer, the next Customer in line becomes the current customer, unless the queue is empty. Whenever, a customer is taken out of the queue, the cashier tallies the total amount time this customer spent waiting in line. If the cashier has no customer and the queue is tingly, there is nothing to be done for this step;
— The cashier serves one item (a call to the method serve() of its current customer):
— If the eminent customer has no more items, the insider adds the number of items of this customer to the tally. The state of this cashier object now indicates that this cashier has no current customer (the customer has been sent away).
There are also 3 instance methods used to report statistics for the total waiting time, total number of items served and total number of customers served by this cashier: int getTotalCustomerWaitTime(), int getTotalitentsServed(), and hi getTotalCustomersServed(). Fitmlly, the String toString() method returns a String that summarizes the statistics of this cashier.
Step by Step Solution
3.42 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
public class Cashier private Queue queue private Customer currentCustomer private int customerWaitTi...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started