Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in Java Create a Statistics class that provides three methods: Factorial permuta

ID: 3886204 • Letter: I

Question


in Java

Create a Statistics class that provides three methods: Factorial permutation, and combination. First, implement the factorial method using a recursion: Feel free to research on recursion to refresh your memory. Second, implement the permutation and combination functions, which use factorial. Again, feel free to research these methods. Create a driver and display the results of the following: Compute 5! Show on screen the number of ways to order 3 items from a pool of 7 items. Show on screen the number of ways to select 2 items from a pool of 8 items.

Explanation / Answer

Output:

Code:

public class Statistics{
static int factorial(int n){
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
public static int permutation(int n,int k ){
int n1 = factorial(n);
int n2 = factorial(n-k);
int r = n1/n2;
return r;

}
public static int combination(int n , int k ){
int n1 = permutation(n,k);
int n2 = factorial(k);
int r = n1/n2;
return r;
}

public static void main(String args[]){
int i,fact=1;
int number=5;
int k = 3;
int n = 7;
int k2 = 2;
int n2 = 8;
fact = factorial(number);   
int p = permutation(n,k);
int c = combination(n2,k2);
System.out.println("factorial of " + number + "is: " + fact );
System.out.println("Permutation of "+n+","+k+" is: "+p);
System.out.println("Combination of "+n2+","+k2+" is: "+c);
}
}