Given knowledge of the average (A) arrival rate of customers at some
business (e.g. bank, post office, shop etc) the likelyhood of a
particular number of customers (X) arriving can be estimated using the
Poisson probability function (named after Siméon Denis Poisson):
Poisson(X) = (AX * e-A)/X!
where X is a number of customer arrivals per minute, A is the average
number of arrivals per minute, X! is factorial(X), and e is Euler's
number (2.7182818). For example if A = 3 them the probability of one
customer entering the premises is:
(31 * 2.7182818-3)/1 = 0.149361
Develop a Java software system which takes as input a user supplied
average arrival rate (A), and calculates and displays the Poisson
probability associated with a range of values for X (numbers of
customers arriving) according to the following:
If A-5 (the average number of customers arriving -5) is greater than
zero a range of A-5 to A+5 incrementing in steps of 1 (e.g. if A = 7,
then X = 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).
Otherwise, becuase we cannot have a negative number of customers
arriving, if A-5 is less than or equal to zero then a range of 1 to
A+5 incrementing in steps of 1 (e.g. if A = 3, then X = 1, 2, 3, 4, 5,
6, 7, 8).
Assume that A is an integer between 1 and 10.
Note 1: You should build at least two classes, one that characterises
the "Poisson probability" problem in general and an application class.
Note 2: To calculate a X! you need to use the Factorial class below.
Once compiled you can create intances of the Factorial class which may
be of use in the solution to the current problem. (Assume that the
Factorial class has been properly designed and tested and thuys will
not rerquire any further design or testing,)
class Factorial {
// ------------------ FIELDS ----------------------
private long numberOfTerms;
private long product;
// ----------------- CONSTRUCTORS -----------------
/* Factorial constructor */
public Factorial(long numTerms) {
numberOfTerms = numTerms;
}
// ------------------ METHODS ---------------------
/* Get product */
public long getProduct() {
return(product);
}
/* Calculate factorial N */
public void factorialN() {
long loopParameter;
final long END_CONDITION = 0;
// Initial value for product
product = 1;
// Loop
for(loopParameter = numberOfTerms; loopParameter > END_CONDITION;
loopParameter--)
product = product*loopParameter;
}
} |