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

The rules of a certain carnival game stipulate that a player throws one standard

ID: 3683528 • Letter: T

Question

The rules of a certain carnival game stipulate that a player throws one standard 6-sided die, one 20-sided die ( with 1 to 20 spots), one 8-sided die( with 1 to 8 spots), one 4-sided die ( 1 to four spots), and one 12-sided die(1 to 12 spots).  The player wins if the total on the five dice is greater than 35 or less than 20.  Write a program that simulates the carnival game 100 times and reports the number of times a player wins.  Your program should include a method
               
                        int dieRoll(int x)



that returns a random number between 1 and x.

Write the program in Java Language

Explanation / Answer

import java.util.*;
public class PS6_7
{
    public static void main(String[]args)
    {
       System.out.println("Carnival Game ");
       int x=0, count=0;
       for (int i=0; i==100; i++)
       {
               dieRoll(x);
               if (x>35&&x<20)
               count++;

       }
           System.out.println("Number of wins out of 100: "+count);
     }

     public static int dieRoll(int x)

     {
           int a=(int)(4*Math.random()+1);

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

           int c=(int)(8*Math.random()+1);

           int d=(int)(12*Math.random()+1);
           int e=(int)(20*Math.random()+1);

           x=a+b+c+d+e;
           return x;  
      }

}

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