Question: This is for Computational structures cs 2130. I need help with 1 and 2 ** please use the java class code to help answer the

This is for Computational structures cs 2130. I need help with 1 and 2

** please use the java class code to help answer the questions directly under this

This is for Computational structures cs 2130. I need help with 1

// Discrete Probability Library

public class DProb

{

public static double Permutations(long N, long X)

{

double perm = 0.0;

return perm;

}

public static double Combinations(long N, long X)

{

double comb = 0.0;

return comb;

}

public static double HyperGeometric(long Np, long Xp, long N, long X)

{

double probX = 0.0;

return probX;

}

public static double Binomial(double P, long N, long X)

{

double probX = 0.0;

return probX;

}

public static double Poisson(double Xmean, long X)

{

double probX = 0.0;

return probX;

}

} // end class

Write a Java "library" class called DProb consisting entirely of static methods (similar to a C function library). This type of class is never instanced as an object, so references to methods use the class name instead of an object name (e.g. DProb.xxx(..)). The DProb class contains functions for calculating permutations, combin ations, and several discrete probability distributions. For each function, use a long datatype for all integer parameters and a double datatype for all decimal parameters. Do not use factorial functions in your algorithms (overflow problems). The return type is double for each function. Your DProb class shoul d inclu de the following functions: Permutation(long N, long x): This function returns the number of ways X objects can be drawn from N objects in a particular order. To reduce the problem of integ er overflow, your algorithm should convert (cast) all values to double while you calculate the result. 1. eg. double perm 1.0 Then in loop: perm-perm(double) (N-i) 2. Combination(long N, long x): This function returns the number of ways X objects can be drawn from N objects ignoring the order in which the objects are drawn. To reduce the problem of integer overflow, your algorithm should: a. For special cases X-0 and X-N, the return value is 1.0 b. Calculate CNX) or CNN-X) depending on whether X or N-X is smaller (sam e value) e.g To calculate C(50,47), calculate C(50,3) instead eg. C(25,4)- 25/1 24/2 * 23/3 22/4 eg. double comb - 1.0 c. Alternate multiplies and divides (in a loop) d. Convert (cast) all values to double while you calculate the result. Then in the loop: combcomb* (double) (N-i)/ (double) (i 1)

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!