Question

In: Computer Science

Java Programming Activity Description: This lab requires you to simulate the rolling of two dice. Two...

Java Programming Activity Description: This lab requires you to simulate the rolling of two dice. Two dice consisting of 6 sides are rolled. Write a program that simulates this. The user will be asked if he/she wishes to continue the roll of dice. If the answer is, “Y” or “y”, then your application will continue to roll the two dice. Each roll of the dice must occur 6 times, each time the user agrees to continue (see sample output). Use a for loop in order to keep track of the number of times the dice are rolled.

Solutions

Expert Solution

Explanation:

Here is the code which has the Scanner object and the Random object.

A while loop is there, which keeps running until the user presses y or Y every time to roll the dice again.

Everytime, the rolls are printed on both the die.

Code:

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

public class Main
{
   public static void main(String[] args) {
      
       Scanner sc = new Scanner(System.in);
       Random r = new Random();
       int first, second;
      
      
       while(true)
       {
       first = r.nextInt(6) + 1;
       second = r.nextInt(6) + 1;
      
       System.out.println("First Dice: "+first+" Second Dice: "+second);
      
       System.out.print("Do you want to roll again? ");
      
       String answer = sc.nextLine();
      
      
       if(!answer.equals("y") && !answer.equals("Y"))
       break;
       }
      
      
   }
}

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!


Related Solutions

Write a Java program to simulate the rolling of two dice. The application should use an...
Write a Java program to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12. Your application should roll the dice 36,000,000 times. Store the results of each roll...
1. Let’s use Excel to simulate rolling two dice and finding the rolled sum. • Open...
1. Let’s use Excel to simulate rolling two dice and finding the rolled sum. • Open a new Excel document. • Click on cell A1, then click on the function icon fx and select Math&Trig, then select RANDBETWEEN. • In the dialog box, enter 1 for bottom and enter 6 for top. • After getting the random number in the first cell, click and hold down the mouse button to drag the lower right corner of this first cell, and...
DESCRIPTION Complete the given program to simulate the roll of two 6-sided dice and count the...
DESCRIPTION Complete the given program to simulate the roll of two 6-sided dice and count the number of rolls of each possible roll value (2 to 12). The number of rolls will be input by the user. Count the rolls of each type and then "draw" a histogram by printing a "*" for each roll of each type. The shape of the histogram will follow the "probability distribution" for large numbers of rolls, i.e., it will show more rolls for...
R Exercise 1. (a) Simulate the rolling of two dice 10,000 times. (b) Identify which rolls...
R Exercise 1. (a) Simulate the rolling of two dice 10,000 times. (b) Identify which rolls of the dice are in the event A, the dice add up to a perfect square (4 or 9). Determine what proportion of the 10,000 rolls are in A. (c) Identify which rolls of the dice are in the event B, the dice add up to an even number. Determine what proportion of the 10,000 rolls are in B. (d) Find out which rolls...
Lets use Excel to simulate rolling two 8-sided dice and finding the rolled sum. • Open...
Lets use Excel to simulate rolling two 8-sided dice and finding the rolled sum. • Open a new Excel document. • Click on cell A1, then click on the function icon fx and select Math&Trig, then select RANDBETWEEN. • In the dialog box, enter 1 for bottom and enter 8 for top. • After getting the random number in the first cell, click and hold down the mouse button to drag the lower right corner of this first cell, and...
Consider rolling a fair dice. You keep rolling the dice until you see all of the...
Consider rolling a fair dice. You keep rolling the dice until you see all of the faces (from number 1 to 6) at least once. What is your expected number of rolls?
Consider the experiment of rolling two dice. You win if you roll a sum that is...
Consider the experiment of rolling two dice. You win if you roll a sum that is at least 7 and at most 12. Find the probability of a win.
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals method to compare two or more objects. Your should use your QC5 as a reference. …………………………...…….. …………………………...……. Instructions LAB5 Instructions Using QC5 as a model, create a Rectangle class and a CompareUsingequalsMethod class that uses an   equals Method to determine if two rectangles are equal if and only if their areas are equal. The Rectangle class should have two instance variables length and width....
Find the probability of rolling a sum of two dice that is a 7 or a...
Find the probability of rolling a sum of two dice that is a 7 or a 12. Round answer to 4 decimal places.
1. Suppose you perform an experiment that consists of rolling two dice and recording their sum....
1. Suppose you perform an experiment that consists of rolling two dice and recording their sum. a. What is the sample space of this experiment? b. Find the probability that the sum is either even or more than 9. c. Find the probability that the sum is odd and a multiple of 3. d. Find the expected sum. 2. When Fernando took MAT 257 last semester, he got the same exact score, 85%, in both Test 1 and Test 2....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT