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

Fill blanks of the following code segment that simulate rolling two six-sided di

ID: 3841799 • Letter: F

Question

Fill blanks of the following code segment that simulate rolling two six-sided dice and getting the sum using discrete() method of StdRandom class on page 226 of the textbook. [5 points]

This is a java program

int sum, eye1, eye2;

____________ p = _________________;

for (int i=0; i<6; i++)
_____________________

eye1 = ________________________;

eye2 = ________________________;

sum = eye1 + eye2

this is StdRandom program from p.226

the question comes from Introduction to Programming in Java

This is the book website: http://introcs.cs.princeton.edu/java/home/

this is StdRandom program from p.226
public class StdRandom
{
    public static int uniform(int N)
    {return (int)(Math.random()*N);}
    public static double uniform(double lo, double hi)
    {return lo +Math.random()*(hi-lo);}
    public static boolean bernoulli(double p)
    {return Math.random()<p;}
    public static double gaussian() {
       
        double r, x, y;
        do {
            x = uniform(-1.0, 1.0);
            y = uniform(-1.0, 1.0);
            r = x*x + y*y;
        } while (r >= 1 || r == 0);
        return x * Math.sqrt(-2 * Math.log(r) / r);
       
       
    }
    public static double gaussian(double m, double s)
    {return m+s*gaussian();}
    public static int discrete(double[] a){
        double r =uniform(0.0,1.0);
        double sum=0.0;
        for(int i=0; i<a.length; i++)
        {
            sum+=a[i];
            if(sum>r)return i;
        }
        return a.length-1;
    }
    public static void main(String[] args)
    {
        int N=Integer.parseInt(args[0]);
        double[]t={.5,.3,.1,.1};
        for(int i=0; i<N; i++)
        {
            StdOut.printf(" %2d " , uniform(100));
            StdOut.printf("%8.5f " , uniform(10.0, 99.0));
            StdOut.printf("%5b " , bernoulli(.5));
            StdOut.printf("%7.5f ", gaussian(9.0,.2));
            StdOut.printf("%2d ", discrete(t));
            StdOut.println();
           
           
           
        }
    }

Explanation / Answer

int sum,eye1,eye2;

dice p= new PairOfDice();

for(int i=0;i<6;i++)

sum count=0;

eye1 = (int)(Math.random()*6) + 1;
eye2 = (int)(Math.random()*6) + 1;

sum = eye1+eye2;

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