Learning Purpose: Practice I Random number generation Use of arrays Sample Output: Sum Frequency...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Learning Purpose: Practice I Random number generation ■ Use of arrays ■ Sample Output: Sum Frequency Percentage 2 1003 3 1980 4 2955 5 4123 6 4908 7 6014 8 4940 9 3932 10 3100 2034 1011 OH Formatted output 11 12 2.8% 5.5% 8.2% 11.5% 13.6% 16.7% 13.7% 10.9% 8.6% 5.7% 2.8% Instructions: Create a new Java file called Dice.java 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. ● 191 M 1 2 3 4 5 6 7 3 4 5 6 7 8 3 4 5 6 7 8 9 5 5 6 7 8 9 10 5 6 7 8 9 10 11 7 00 8 의 10 11 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) Learning Purpose: Practice I Random number generation ■ Use of arrays ■ Sample Output: Sum Frequency Percentage 2 1003 3 1980 4 2955 5 4123 6 4908 7 6014 8 4940 9 3932 10 3100 2034 1011 OH Formatted output 11 12 2.8% 5.5% 8.2% 11.5% 13.6% 16.7% 13.7% 10.9% 8.6% 5.7% 2.8% Instructions: Create a new Java file called Dice.java 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. ● 191 M 1 2 3 4 5 6 7 3 4 5 6 7 8 3 4 5 6 7 8 9 5 5 6 7 8 9 10 5 6 7 8 9 10 11 7 00 8 의 10 11 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)
Expert Answer:
Answer rating: 100% (QA)
Program import javautilRandom public class Dice public static void mainString args variable declarat... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
In Problems 4750, match each graph with the correct equation. (a) (x 3) 2 + (y + 3) 2 = 9 (b) (x + 1) 2 + (y 2) 2 = 4 (c) (x 1) 2 + (y + 2) 2 = 4 (d) (x + 3)2 + (y 3) 2 = 9 -6 -5 -4 -3 -2 ko 6 -5...
-
Two franchising experts recently debated the issue of whether new college graduates should consider franchising as a pathway to entrepreneurship. Jeff Elgin said recent college graduates are not...
-
What two measures help protect a government from failure on a contractor's part to comply with the terms and specifications of a construction agreement? Describe each measure and its primary purpose.
-
Comparative financial statement data for Carmono Company follow: Assets Cash Accounts receivable Inventory Total current assets Property, plant, and equipment Less accumulated depreciation Net...
-
How many degrees of freedom are there? Exercises 1015 refer to the following data: Anthropologists can estimate the birthrate of an ancient society by studying the age distribution of skeletons found...
-
Your client is a company that owns a shopping center with 30 store tenants. All leases with the store tenants provide for a fixed rent plus a percentage of sales, net of sales taxes, in excess of a...
-
1. Law in Canada is derived from the Constitution, statutes, precedents, and equity; Roman law is not relevant. 2. Consequences of stare decisis - precedents are legally binding 3. What does...
-
1. Which of the two basic reporting approaches for the cash flows from operating activities did Lowes use? Is this the same as what The Home Depot used? 2. What amount of cash did Lowes receive from...
-
Which of the following is NOT true regarding scope creep? A. It is the tendency for the project scope to expand overtime B. It can have both positive and negative impacts on aproject C. It most...
-
A roller coaster has 6 circular loops with varying radii. Given the speed of the cart through each loop, rank the force from the track on the cart at the bottom of each loop. What loop will make you...
-
A water tower holds water in both the cylindrical and bottom spherical part of the tank. The radius of the tank is 15' and the bottom part is a perfect hemisphere. Currently there is 18,000 ft3 of...
-
An Acapulco cliff diver in (m = 70.0 kg) jumps 30.0 meters from the top of the cliff toward the ocean below. However, in a freak accident, half-way down 8.00 meters from his launch point, he crashes...
-
1. Discuss the various kinds of crime classifications. To what extent or degree are they distinguishable? 2. List the problems faced by todays police departments that were also present during the...
-
an electric field of 4000 N/c is in the +x direction. a charge of 3.00 C is moved a distance of 2.50 cm at an angle of 40 with the x+ direction. what is the potential difference (in V) from the...
-
Question 15/24 When multiple team members are working on a related feature, how often should they integrate their work? Select only one answer. Do the integration midway through the iteration. After...
-
Why can wastewater treatment requirements in Hawaii be less stringent than those in most locations on the U.S. mainland?
-
Jim (age 50) and Martha (age 49) are married with three dependent children. They file a joint return for 2012. Their income from salaries totals $50,000, and they received $10,000 in taxable...
-
Frank, age 35, and Joyce, age 34, are married and file a joint income tax return for 2012. Their salaries for the year total $83,000 and they have taxable interest income of $4,000. They have no...
-
For each of the following situations, indicate whether the taxpayer(s) is (are) required to file a tax return for 2012. Explain your answer. a. Helen is a single taxpayer with interest income in 2012...
-
The rotor shown in Fig. 9.44 (a) is balanced temporarily in a balancing machine by adding the masses \(m_{1}=m_{2}=90 \mathrm{~g}\) in the plane \(A\) and \(m_{3}=m_{4}=90 \mathrm{~g}\) in the plane...
-
A turbine rotor is run at the natural frequency of the system. A stroboscope indicates that the maximum displacement of the rotor occurs at an angle \(229^{\circ}\) in the direction of rotation. At...
-
The cylinders of a four-cylinder in-line engine are placed at intervals of \(300 \mathrm{~mm}\) in the axial direction. The cranks have the same length, \(100 \mathrm{~mm}\), and their angular...
Study smarter with the SolutionInn App