Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tasks of Chapter 4 This is a simulation of rolling dice. Actual results approach theory only when the sample size is large. So, we will

image text in transcribed
image text in transcribed
Tasks of Chapter 4 This is a simulation of rolling dice. Actual results approach theory only when the sample size is large. So, we will need to repeat rolling the dice a large number of times we will use 10,000). The theoretical probability of rolling doubles of a specific number is 1 out of 36 or approximately 278 out of 10,000 times that you roll the pair of dice. Since this is a simulation, the numbers will vary a little each time you run it. Check out how to use the random number generator introduced in Section 4.11 of the text) to get a number between 1 and 6 to create the simulation. Task #1 The while Loop 1. Copy the file Dice Simulation java (see Code Listing 4.1) from the Student Files or as directed by your instructor. DiceSimulation.java is incomplete. Since there is a large part of the program missing, the output will be incorrect if you run it. 2. All the variables are declared. 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. 3. 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 4. To "roll" the dice, use the nextInt method of the random number generator to generate an integer from 1 to 6. 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 5. Compile and run. 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago