subject

1) Open the file DiceSimulation. java attached below. Create a new project on NetBeans called DiceSimulation. Copy the code from the file into it. Note that DiceSimulation. java is incomplete. Since there is a large part of the program missing, the output will be incorrect if you run DiceSimulation. java.

2) I have declared all the variables. You need to add code to simulate rolling the dice and keeping track of the doubles. Convert the algorithm below into Java code and place it in the main method after the variable declarations, but before the output statements. You will be using several control structures: a while loop and an if-else-if statement nested inside another if statement. Use the indenting of the algorithm to help you decide what is included in the loop, what is included in the if statement, and what is included in the nested if-else-if statement.

Repeat while the number of dice rolls are less than the number of times the dice should be rolled.

Get the value of the first die by "rolling" the first die

Get the value of the second die by "rolling" the second die

If the value of the first die is the same as the value of the second die

If value of first die is 1

Increment the number of times snake eyes were rolled

Else if value of the first die is 2

Increment the number of times twos were rolled

Else if value of the first die is 3

Increment the number of times threes were rolled

Else if value of the first die is 4

Increment the number of times fours were rolled

Else if value of the first die is 5

Increment the number of times fives were rolled

Else if value of the first die is 6

Increment the number of times sixes were rolled

Increment the number of times the dice were rolled

Note: To "roll" the dice, use the nextInt method of the random number generator to generate an integer between 1 and 6.

3) Compile and run you program. You should get numbers that are somewhat close to 278 for each of the different pairs of doubles. Run it several times. You should get different results than the first time, but again it should be somewhat close to 278.

//

Task #2 Using Other Types of Loops

1) Change the while loop to a do-while loop. Compile and run. You should get the same results.

2) Change the do-while loop to a for loop. Compile and run. You should get the same results.

//

Code Listing 4.1 (DiceSimulation. java)

import java. util. Random; // Needed for the Random class

/**

This class simulates rolling a pair of dice 10,000 times and counts the number of times doubles of are rolled for each different pair of doubles.

*/

public class DiceSimulation

{

public static void main(String[] args)

{

final int NUMBER = 10000; // Number of dice rolls

// A random number generator used in

// simulating the rolling of dice Random generator = new Random();

int die1Value; // Value of the first die

int die2Value; // Value of the second die

int count = 0; // Total number of dice rolls

int snakeEyes = 0; // Number of snake eyes rolls

int twos = 0; // Number of double two rolls

int threes = 0; // Number of double three rolls

int fours = 0; // Number of double four rolls

int fives = 0; // Number of double five rolls

int sixes = 0; // Number of double six rolls

// TASK #1 Enter your code for the algorithm here

// Display the results

System. out. println ("You rolled snake eyes " + snakeEyes + " out of " + count + " rolls.");

System. out. println ("You rolled double twos " + twos + " out of " + count + " rolls.");

System. out. println ("You rolled double threes " + threes + " out of " + count + " rolls.");

System. out. println ("You rolled double fours " + fours + " out of " + count + " rolls.");

System. out. println ("You rolled double fives " + fives + " out of " + count + " rolls.");

System. out. println ("You rolled double sixes " + sixes + " out of " + count + " rolls.");

}

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:00
The two main ways in which marketers address the competition with their strategies are by satisfying a need better than a competition and by
Answers: 2
question
Computers and Technology, 22.06.2019 18:00
Suppose an astronomer discovers a large, spherical-shaped body orbiting the sun. the body is composed mostly of rock, and there are no other bodies sharing its orbit. what is the best way to categorize this body? a. planet b. moon c. comet d. asteroid
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
The computers in the sales department did not have enough data storage capacity to contain all the information the department needed to store, and it was taking a long time for team members to access the data they needed. to fix the problem, the technician installed new, larger hard drives on all the computers.
Answers: 1
question
Computers and Technology, 23.06.2019 21:40
Simon says is a memory game where "simon" outputs a sequence of 10 characters (r, g, b, y) and the user must repeat the sequence. create a for loop that compares the two strings. for each match, add one point to user_score. upon a mismatch, end the game. sample output with inputs: 'rrgbryybgy' 'rrgbbrybgy'
Answers: 3
You know the right answer?
1) Open the file DiceSimulation. java attached below. Create a new project on NetBeans called DiceSi...
Questions
question
Chemistry, 16.10.2020 19:01
question
Mathematics, 16.10.2020 19:01
question
Computers and Technology, 16.10.2020 19:01
question
Spanish, 16.10.2020 19:01
question
Mathematics, 16.10.2020 19:01
question
Biology, 16.10.2020 19:01
question
Mathematics, 16.10.2020 19:01
Questions on the website: 13722367