Question

Write a program to simulate rolling three dices simultaneously. Keep rolling these three dices until the...

Write a program to simulate rolling three dices simultaneously. Keep rolling these
three dices until the three dices show the values of “1”, “2”, and “3” (we call this
condition 1. The dices are in no particular orders to show these values in this case).
Then the program shows the values of the three dices and the number of rolling so
far. After that the rolling continues (and counting of the number of rolling
continues too) until the first dice shows the value of “1” while condition 1 is also
satisfied. Your program then shows the total number of rolling and stops. You are
encouraged to simplify the logical expressions, with less operands and operators,
used in your program.
The output of your program is similar to:
Number of rolling Value1 Value2 Value3
38 3 1 2
83 2 1 3
157 3 1 2
177 1 2 3
Total number of rolling: 177
This should be for a java program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Random;

public class Roll123 {

    public static void main(String[] args) {
        int count = 0, n1, n2, n3;
        Random random = new Random();
        System.out.println("Number of rolling Value1 Value2 Value3");
        while (true) {
            count++;
            n1 = random.nextInt(6) + 1;
            n2 = random.nextInt(6) + 1;
            n3 = random.nextInt(6) + 1;
            if (n1 == 1 && n2 == 2 && n3 == 3) {
                System.out.println(count + " 1 2 3");
                break;
            }
            if ((n1 == 1 || n2 == 1 || n3 == 1) && (n1 == 2 || n2 == 2 || n3 == 2) && (n1 == 3 || n2 == 3 || n3 == 3)) {
                System.out.println(count + " " + n1 + " " + n2 + " " + n3);
            }
        }
        System.out.println("Total number of rolling: " + count);
    }
}

Add a comment
Know the answer?
Add Answer to:
Write a program to simulate rolling three dices simultaneously. Keep rolling these three dices until the...
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 will simulate rolling a die. When rolling a die, one will...

    Write a C PROGRAM that will simulate rolling a die. When rolling a die, one will get a die face value of 1-6. We can use rand function and math ceiling function to get a random number of 1-6 generated. The program will simulating rolling 5 dice simultaneously and store their face values into an array of size 5. The program will keep rolling the dice and print the following: 1. All face values in one line 2. If any...

  • Write a program that calls the random number generator two times to simulate rolling a pair...

    Write a program that calls the random number generator two times to simulate rolling a pair of dice. It should store the two numbers into variables. It will then determine if the dice roll is a winner (doubles OR add up to 7). Remember to add two includes and also to seed the random number generator to the clock. This will roll two dice and add them together. Doubles, or a total of 7 - YOU ARE A WINNER!!! First...

  • ( Java Programming ) Write an application to simulate the rolling of two dice. The application...

    ( Java Programming ) Write an application 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, with 7 being the most frequent sum, and 2 and 12...

  • PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll...

    PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this: 6,4,1,3,1 Write a script that will simulate the roll...

  • please do it in C++ Write a program that simulates the rolling of two dice. The...

    please do it in C++ Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. 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 2and 12...

  • 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...

  • this is a C++ program! You will write a program that performs the following tasks for...

    this is a C++ program! You will write a program that performs the following tasks for a simple mathematical calculator: (1) Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file...

  • Write a program to Simulate a game of tic tac toe in c#

    Write a program to Simulate a game of tic tac toe. A game of tic tac toe has two players. A Player class is required to store /represent information about each player. The UML diagram is given below.Player-name: string-symbol :charPlayer (name:string,symbol:char)getName():stringgetSymbol():chargetInfo():string The tic tac toe board will be represented by a two dimensional array of size 3 by 3 characters. At the start of the game each cell is empty (must be set to the underscore character ‘_’). Program flow:1)    ...

  • Operating System Theory and Design Write a program to simulate the operation of two of CPU...

    Operating System Theory and Design Write a program to simulate the operation of two of CPU scheduling methods. The program does the following: 1. Get the number of processes from the user. 2. Get the burst time of each process from the user 3. Assume that all processes arrive at "O" to the ready queue. 4. The program lets the user select one of the two methods to implement the o e oo implement the CPU scheduling. time. You can...

  • 2. Let's now use Excel to simulate rolling two 6-sided dice and finding the minimum of...

    2. Let's now use Excel to simulate rolling two 6-sided dice and finding the minimum of both dice. • Create a new Excel sheet in your document. Click on cell Al, then click on the function icon f. 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...

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