Google Answers Logo
View Question
 
Q: Java Programming - Poisson Probability ( No Answer,   1 Comment )
Question  
Subject: Java Programming - Poisson Probability
Category: Computers > Programming
Asked by: java_design-ga
List Price: $15.00
Posted: 30 Nov 2005 09:56 PST
Expires: 03 Dec 2005 02:21 PST
Question ID: 599530
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;
	}    			
    }

Request for Question Clarification by answerguru-ga on 01 Dec 2005 00:42 PST
Hi java_design-ga,

I'd like to help with this but your list price is on the low side. If
you don't get any other takers, I could do this for you for $50.

Thanks,
answerguru-ga

Clarification of Question by java_design-ga on 01 Dec 2005 04:12 PST
i'll consider it!
Answer  
There is no answer at this time.

Comments  
Subject: Re: Java Programming - Poisson Probability
From: internetjanitor-ga on 01 Dec 2005 15:19 PST
 
// -----------------------
// PoissonDemo.java
// -----------------------

import java.text.DecimalFormat;
 
public class PoissonDemo {

	public static void main(String[] args) {
		long average = 2;

		Poisson p = new Poisson(average);
		DecimalFormat df = new DecimalFormat("0.000000");
		
		System.out.println("Number of |   Poisson");
		System.out.println("Customers | Probability");
		System.out.println("   (X)    |    A = " + average);
		System.out.println("----------+------------");

		if (average < 5) {
			for (long x = 1; x <= average + 5; x++) {
				System.out.println("    " + x + "\t  |  "
						+ df.format(p.getProbability(x)));
			}
		} else {
			for (long x = average - 5; x <= average + 5; x++) {
				System.out.println("    " + x + "\t  |  "
						+ df.format(p.getProbability(x)));
			}
		}
	}
}

// -----------------------
// Poisson.java
// -----------------------

public class Poisson {
	private double average = 0;
	
	public Poisson(double average) {
		this.average = average;
	}
	public double getProbability(long x) {
		// P(x) = µ^x · e^-µ ÷ x!
		
		Factorial f = new Factorial(x);
		f.factorialN();
		
		return (Math.pow((double)average,(double)x) *
Math.pow(Math.E,(double)(0-average)) / f.getProduct());
	}
}

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy