Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the code for the excercise(image) below? Use a similar context as the given code show below- import java.util.Random; public class DemoRollDice { private

What is the code for the excercise(image) below?

Use a similar context as the given code show below-

import java.util.Random;

public class DemoRollDice { private static Random rand = new Random(); private static final int SIZE_OF_DIE = 6; // number of sides public static void main(String[] args) { demoSingleDie(); demoRollingThreeDice(); rollThreeDice(); } // Simulate rolling a single die private static void demoSingleDie() { // roll die 10 times and print the results in one line for (int i = 0; i

--------------------------------------------------------------

What is the code in Java for the exercise below?

image text in transcribed

CS1400 A09 - Dice Instructions: Learning Purpose: Practice Random number generation Create a new Java file called Dice.java Use of arrays Formatted output Simulate the rolling of 2 dice Do that by creating one single object of type Random and by reusing it to roll the first die and then the second die Once both dice have been rolled calculate the sum of the two values. Use a one-dimensional integer array to count how often each sum appears. When rolling two dice the sum will be a value from 2 12. However, not every sum has the same probability of being rolled E.g.: There are three ways to roll a sum of 4, six ways to roll a sum of 7 but only one way to roll a sum of 12. Sample Output: Sum Frequency Percentage 2.8% 5.58 8.2% 1003 1980 2955 4123 4908 6014 4940 3932 3100 2034 1011 13.6% 16.7 13.7% 10.9 3 8.6% 578 2.8% 1.0 1.2 10 10 11 789 111 12 Roll the two dice 36,000 times. Display the results in a tabular format like in the sample output. Start with a header line (Sum, Fequency, and Percentage) and list the numbers in right aligned columns. The percentage should display only one digit after the decimal point In order to output % within a format string write %% Tip: Check whether the results are reasonable (e.g. the sum 7 should be rolled about 1/6 of the time)

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

Step: 3

blur-text-image

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago