Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

// 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

arraylist

Answered: 1 week ago