Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Customer Write a class for modeling a customer. A customer knows its arrival time, its initial number of items, as well as the number

1 Customer

Write a class for modeling a customer. A customer knows its arrival time, its initial number of items, as well as the number of items remaining to be processed. The maximum number of items per customer is (MAX NUM ITEMS). Make sure you identified instance variables and class variables.

The constructor has a single parameter. It specifies the arrival time. The initial number of items is determined when the object is first created using the following formula:

MAX_NUM_ITEMS * Math.random() + 1

Since, Math.random() generates a random number greater than or equal to 0.0 and less than 1.0, the expression MAX_NUM_ITEMS * Math.random() generates a number greater than or equals to 0.0 and less than MAX_NUM_ITEMS, adding 1 ensures that the number of items is greater than or equals to 1.0 but lower than MAX_NUM_ITEMS + 1. This real value is then converted to an int, in the range 1 to MAX_NUM_ITEMS (here, I wanted to make sure that no customer would show up empty handed).

The instance methods of a customer include:
• int getArrivalTime() returns the arrival time;
• int getNumberOfItems() returns the number of items remaining to be processed;
• int getNumberOfServedItems() returns the number of items that have been processed; • serve() decrements by one the number of items of this customer.

2 Cashier

A cashier is responsible for helping a queue of customers. It serves one customer at a time. Since the simulation is used to produce statistics, a cashier also memorizes the total number of customers 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 single constructor. It has no parameters. It initializes the instance variables of the cashier.

The method addCustomer( 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 each cashier is called once for each step of the simulation. The parameter cur- rentTime is used to compute 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 empty, 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 current customer has no more items, the cashier 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 getTotalItemsServed(), and int getTotalCustomersServed(). Finally, the String toString() method returns a String that summarizes the statistics of this cashier. 

Step by Step Solution

3.49 Rating (146 Votes )

There are 3 Steps involved in it

Step: 1

Simulationjava public class Simulation Constants private static f... 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

Document Format ( 2 attachments)

PDF file Icon
6360ae7bb6d78_232836.pdf

180 KBs PDF File

Word file Icon
6360ae7bb6d78_232836.docx

120 KBs Word File

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

Mathematical Statistics With Applications In R

Authors: Chris P. Tsokos, K.M. Ramachandran

2nd Edition

124171133, 978-0124171138

More Books

Students also viewed these Accounting questions