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

For this exercise. write a code that mimics Excel?s BINOM.DIST functionality. Fo

ID: 653364 • Letter: F

Question

For this exercise. write a code that mimics Excel?s BINOM.DIST functionality. For example, >java Binomdist 2 10 0.4 0. 109335199999997 Include the following when you submit your assignment: 1. Your code file (should be plain text with a . java extension) and the class file (with a . c1a33 extension). The code should have comments explaining what each method does In the Doc comments. include a brief explanation of how to execute your class: ?, * Compilation: javac Binomdist.java * Execution: java Binomdist x n p * Dependent libraries: List any here * * Reads in x, n. and p as command-line arguments and prints out binomial probability. * Sample output * > java Binomial 2 10 0.4 * 0.12093235199999997

Explanation / Answer

import java.util.Scanner;

public class Binomdist {

@SuppressWarnings("resource")

   public static void main(String[] args) {

       Scanner input = new Scanner(System.in);

       int x = input.nextInt();

       int n = input.nextInt();

       double p = input.nextDouble();

       System.out.println(getBinomdist(x, n, p));

   }

   public static long binomial(int x, int n) {

       if (x > n - x)

           x = n - x;

       long b = 1;

       for (int i = 1, m = n; i <= x; i++, m--)

           b = b * m / i;

       return b;

   }

   public static double getBinomdist(int x, int n, double p) {

       long binomialCoefficient = binomial(x, n);

       double result = binomialCoefficient * Math.pow(p, x)

               * Math.pow(1 - p, n - x);

       return result;

   }

}

Tested Enter 3 values

2

10

0.4

0.12093235199999998

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote