Given knowledge of the averrage (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 then 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 (the average number of customers arriving) is greater than five 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 is less than or equal to five 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.
EXAMPLE 1: Given A=9 (thus A-5 > 0) then the output would be on the
following lines:
Number of | Poisson
Customers | Probability
(X) |
----------+------------
4 | 0.033737
5 | 0.060727
6 | 0.091091
7 | 0.117117
8 | 0.131756
9 | 0.131756
10 | 0.118581
11 | 0.097021
12 | 0.072765
13 | 0.050376
14 | 0.032384
EXAMPLE 2: Given A=2 (thus A-5 <= 0) the output will be of the form:
Number of | Poisson
Customers | Probability
(X) |
----------+------------
1 | 0.270671
2 | 0.270671
3 | 0.180447
4 | 0.090224
5 | 0.036089
6 | 0.012030
7 | 0.003437
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! (factorial X) make use of the Factorial
class presented below. Once compiled you can create
intances of the Factorial class which may be of use in the solution to
the current problem.
Note 3: Euler's constant can be found in the Math class where it is
defined as a class field and can thus be accessed by linking it to the
name of the class, Math.E .
FACTORIAL CLASS:
class Factorial
{
private long numberOfTerms;
private long product;
public Factorial(long numTerms) {
numberOfTerms = numTerms;
}
public long getProduct() {
return(product);
}
public void factorialN() {
final long startCondition = 1;
// Initial value for product
product = 1;
// Loop
for(long loopParameter = startCondition; loopParameter <=
numberOfTerms;loopParameter++)
product = product*loopParameter;
}
} |