Question: Write a java Binomial class to implement a Binomial random variable . Private instance variables for the class should include: double P - probability of

Write a java Binomial class to implement a Binomial random variable. Private instance variables for the class should include:

double P - probability of a success in any one trial.

long N - number of independent trials.

long X - the number of successes in the N trials.

The class methods should include:

appropriate constructor(s).

appropriate get and set methods for the instance variables.

long randomX() - generates a new random value for X.

double mean() - calculates the mean of the random variable [= N*P].

double variance() - calculates the variance of random variable [= N*P*(1-P)].

double probX() - calculates the Binomial probability for the current X value.

Write a program that uses the Binomial class to solve the following problems:

1. For the Binomial distribution defined by P = 0.36 and N = 22:

a. Output P and N.

b. Generate a random value for X, and then output that value.

c. Output the mean of the distribution.

d. Output the variance of the distribution

2. For the Binomial distribution defined by P = 0.73 and N = 6, output the probability distribution of X. That is, for each value of X from 0 to 6, show the X-value together with the probability for that value. Output format should be:

X Pr(X)

0 ...

1 ...

... ...

6 ...

3. For the Binomial distribution defined by P = 0.32 and N = 12:

a. Generate 100 random variable values.

b. Calculate the average of these generated values [= (X1 + X2 + ... + X100)/100].

c. Calculate the theoretical mean of this probability distribution using the mean() method.

d. Compare the values obtained in 3b and 3c. How close are they? Why aren't the values identical?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!