Question

Write an application that: 1. Prompts the user for a number of trials to perform (I will call this N). This operation shoul

in java

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================


import java.util.Random;
import java.util.Scanner;

public class Trials {

    public static void main(String[] args) {

        int[] sumCount = new int[11];
        int trials = 0;
        Scanner scanner = new Scanner(System.in);
        // using try catch to make it type safe

        System.out.print("Enter the number of trials: ");
        trials = (int) scanner.nextDouble();
        Random random = new Random();
        int diceOne = 0, diceTwo = 0;
        for (int trial = 1; trial <= trials; trial++) {
            diceOne = random.nextInt(6) + 1;
            diceTwo = random.nextInt(6) + 1;
            int sum = diceOne + diceTwo;
            sumCount[sum - 2] += 1;
        }

        System.out.printf("\n%10s%10s%10s\n", "Outcome", "Number", "Percent");
        for (int i = 0; i < sumCount.length; i++) {
            System.out.printf("%10d%10d%9.1f%1s\n", i + 2, sumCount[i],
                    sumCount[i] * 100.0 / trials, "%");
        }

    }
}

===================================================================

I 1: Project Trials.java Import java.util. Random import java.util.Scanner; public class Trials { public static void main(Str

===========================================================================

Thank you so much! Please do appreciate it with an upvote!

Thanks, let me know for any questions or in case you encounter any issue.

Please do give a thumbs up from your end : )

I 1: Project Trials.java Import java.util. Random import java.util.Scanner; public class Trials { public static void main(String[] args) { int[] sumCount = new int[11]; int trials = 0; Scanner scanner = new Scanner(System.in); // using try catch to make it type safe try { System.out.print("Enter the member of trials: "); trials = scanner.nextInt (); Random random = new Random(); int diceOne = 0, diceTwo = 0; Trials > main Trials Enter the number of trials: 300 Run: → Outcome Number If | structure EcoJoon Percent 3.38 7.03 7.33 8.73 10.38 19.78 18.73 9.08 7.38 5.38 3.33 2. Favorites 26 Process finished with exit code o 49 Run E : TODO ferminat su: Messages Compilation completed successfully with 3 warnings in 2 s 111 ms (moments ago)

Add a comment
Know the answer?
Add Answer to:
in java Write an application that: 1. Prompts the user for a number of trials to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program that prompts the user for the number for times the user wants...

    Write a C program that prompts the user for the number for times the user wants to flip a coin. Your program will flip a virtual coin that number of times and return the following: 1) The number of times heads occurred. 2) The number of times tails occured. Then take the coin flip program and modify the random number generator to roll a single 6-sided dice.   DO NOT DISPLAY THE RESULTS OF EACH ROLL. 1) Ask the user how...

  • Java programming Write a simulation of the Craps dice game. Craps is a dice game that...

    Java programming Write a simulation of the Craps dice game. Craps is a dice game that revolves around rolling two six-sided dice in an attempt to roll a particular number. Wins and losses are determined by rolling the dice. This assignment gives practice for: printing, loops, variables, if-statements or switch statements, generating random numbers, methods, and classes. Craps game rules: First roll: The first roll (“come-out roll”) wins if the total is a 7 or 11. The first roll loses...

  • (java) Write a While loop that prompts the user for only even numbers. Keep prompting the...

    (java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...

  • (1 point) Using an if Statement In a Loop A common thing to do is to...

    (1 point) Using an if Statement In a Loop A common thing to do is to use variables to keep track of some sort of count. When used in a loop we count things very quickly. Scenario: If you roll a pair of dice, rolling a 12 (two sixes) is rare. How rare? If you were to roll a pair of dice 1,000 times, on average, how many times would it come up as 12? To figure this out, we...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • Self-check exercise: While-loops The value of (π^2)/8 can be approximated by the series Write a script...

    Self-check exercise: While-loops The value of (π^2)/8 can be approximated by the series Write a script that evaluates this expression, ignoring all terms that are strictly smaller than .000001. Your script should display the number of terms summed and the sum. Use a while-loop. Think about the initialization of your variables and the order of computation carefully! In the loop body you need to calculate the value of a term only once. We use the above series for approximating (π^2)/8...

  • Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you...

    Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT