Google Answers Logo
View Question
 
Q: Java Programming ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Java Programming
Category: Computers > Programming
Asked by: strongbow69-ga
List Price: $15.00
Posted: 24 Nov 2002 15:26 PST
Expires: 24 Dec 2002 15:26 PST
Question ID: 113842
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;
	}    			
    }
Answer  
Subject: Re: Java Programming
Answered By: seizer-ga on 24 Nov 2002 16:45 PST
Rated:5 out of 5 stars
 
Hi there strongbow. It's a pleasure to be able to answer another of
your questions.

The code is available in ZIP format at:
http://xult.org/strongbow/poisson.zip

You can also download the classes individually from:

* http://xult.org/Factorial.java
* http://xult.org/Poisson.java
* http://xult.org/Range.java
* http://xult.org/UI.java

Let me give you a quick overview of the code I have created for you.
There are four classes:

* The Factorial class (already given) which calculates a factorial
result.
* The Poisson class which performs a generic Poisson calculation.
* The Range class which sets up an array of values for "X"
* The UI class (short for "User Interface") which utilizes all these
classes to a successful result.

Simply compile all the java files, and run the UI class. It will ask
for the arrival rate ("A"), and the rest will be automated.

I have assumed (as the question specifies) that A will be between 1
and 10. I have tested it successfully for these inputs, noting the
expected bell curve result.

I have included comments, but if you wish some clarification on any
aspect of this program, please ask before rating this answer.

Thanks again, and good luck.

--seizer-ga
strongbow69-ga rated this answer:5 out of 5 stars
Excellent answer, exactly what I needed.

Comments  
There are no comments at this time.

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