Question

In: Computer Science

Roll dice java program The program simulates a dice roll by generating a random integer between...

Roll dice java program

The program simulates a dice roll by generating a random integer between 1 and 6

Solutions

Expert Solution

Hope this will help you. If you have any doubt please let me know.

If you want any modification in the program please let me know. I will do it, because there was no other instruction provided in the program.

Please go through all the notes.

Notes: There were no other instructions or restrictions provided in the problem statement except generate Random number.

There are 2 ways we can generate a random number 1) using Math class and 2) using a Random Class.

Over here not specified which one to use hence both are provided in code. Method using a math class is commented if you want to use this uncomments that line.

All line of code is commented.

A screenshot of the output is also attached.

If you want any modification in the program please let me know. I will do it.

---------------------------------------Coding--------------------------------------


import java.util.Scanner;/*to read user input*/
import java.util.Random; /*for random number*/

public class RollDiceSimulation{ /*class */
   public static void main(String[] args){ /*main*/
       int n; /*int n to print a value */
       Scanner sc= new Scanner(System.in); /*scanner class to read an input for user */
       Random rand = new Random(); /*random class object*/
char ch; /*to read a character*/
       do {
   System.out.print("Face values of the dice is: "); /*print message*/
   n=rand.nextInt(6)+1;/*random number generator between 1 and 6 nextInt(6) generate random number between 0 and 5 and adding 1 into it makes between 1 to 6*/
   //n=(int) (Math.random()*6+1);/*2nd method to generate a random number */
   System.out.println(n); /*printing a dice value*/
   System.out.print("Do you want to countinue? (Press Y for yes, or any other character for no.)"); /*asking for other input*/
   ch=sc.next().charAt(0);/*scanning a first char*/
}while(ch=='Y'||ch=='y');/*if ch==y again roll dice*/
   System.out.println("-----SIMULATION ENDS---------");/*printing a msg*/
   }
}

-----------------------------------Screen-shot--------------------------------------


Related Solutions

. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] The following table shows the 36 possible combinations of the two dice. Your program should...
1. Write a program which simulates rolling dice. It should: Display the random number rolled Ask...
1. Write a program which simulates rolling dice. It should: Display the random number rolled Ask the user if they want to roll again. If they don't want to roll again, the program should end. If they do want to roll again, the new number should display. At a minimum, the die should have 6 sides, but if you want to use a d12 or d20, that is fine too. USE PYTHON
Write a JAVA program that emulates a Magic Eight Ball. Start by generating a random number...
Write a JAVA program that emulates a Magic Eight Ball. Start by generating a random number and then use a switch statement to display the message. Use this website as a resource on possible answers a Magic Eight Ball gives: https://en.wikipedia.org/wiki/Magic_8-Ball
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the...
Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the total on the dice comes up to be a given number. Ask the user for the number that you are rolling for. To have your program roll two dice, use the rand() function this way: die1 = rand() % 6 + 1; die2 = rand() % 6 + 1; Your program then computes and prints the number of rolls it takes to get the...
A program for generating random numbers on a computer is to be tested. The program is...
A program for generating random numbers on a computer is to be tested. The program is instructed to generate 100 single-digit integers between 0 and 9. The frequencies of the observed integers were as follows. At the 0.05 level of significance, is there sufficient reason to believe that the integers are not being generated uniformly? Integer 0 1 2 3 4 5 6 7 8 9 Frequency 9 7 9 6 10 14 8 10 12 15 (a) Find the...
A program for generating random numbers on a computer is to be tested. The program is...
A program for generating random numbers on a computer is to be tested. The program is instructed to generate 100 single-digit integers between 0 and 9. The frequencies of the observed integers were as follows. At the 0.05 level of significance, is there sufficient reason to believe that the integers are not being generated uniformly? Integer 0 1 2 3 4 5 6 7 8 9 Frequency 9 7 9 6 10 14 8 10 12 15 (a) Find the...
A program for generating random numbers on a computer is to be tested. The program is...
A program for generating random numbers on a computer is to be tested. The program is instructed to generate 100 single-digit integers between 0 and 9. The frequencies of the observed integers were as follows. At the 0.05 level of significance, is there sufficient reason to believe that the integers are not being generated uniformly? Integer 0 1 2 3 4 5 6 7 8 9 Frequency 10 8 7 9 13 11 5 9 14 14 (a) Find the...
A program for generating random numbers on a computer is to be tested. The program is...
A program for generating random numbers on a computer is to be tested. The program is instructed to generate 100 single-digit integers between 0 and 9. The frequencies of the observed integers were as follows. At the 0.05 level of significance, is there sufficient reason to believe that the integers are not being generated uniformly? Integer 0 1 2 3 4 5 6 7 8 9 Frequency 12 9 7 7 12 12 6 8 12 15 (a) Find the...
Suppose we roll a fair dice thrice in such a way that the assumption of random...
Suppose we roll a fair dice thrice in such a way that the assumption of random sampling is satisfied. Let {X1;X2;X3} be the numbers coming up in the first three throws. Let their sample average be X3= (1/3) * ((X1+X2+X3)) 1) Write down the sampling distribution ofX3. To this end, you need to write down a table that contains all values that X3 can take on together with their probabilities. 2) What is the probability that X3 greater than equal...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT