Write a program named Dice.java that will do the following: 1. Ask the user how many...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program named Dice.java that will do the following: 1. Ask the user how many times they wish to roll a pair of dice, from 1-999. Validate the input-keep asking until the number is in range. Write a method named getNRolls() to do this step. The method takes a scanner object as its parameter and returns the number of rolls the user desires. 2. Create a 6 x 6 array named rolls to hold the result of the rolls. 3. Simulate randomly rolling a pair of dice as many times as the user requested. As you roll the dice, count how many times each combination of dice was rolled. For example, if the first die is a 3 and the second die is 5, you will add one to the entry at rolls [2][4]. (If you generate numbers in the range 1-6, you will have to subtract one at appropriate places. If you generate numbers in the range 0-5, you don't need to do any subtraction). Write a method named rolldice() to do this step. It takes the number of rolls as its parameter and returns the two-dimensional array of rolls. 4. Print out the array, properly labeled, so that the numbers all line up. You can do this in main() or write a method to do it. 5. Go through the array you created in step 3 and figure out how many times the dice totaled 2, 3, 4. ... 12. Write a method called calcFrequencies ()) to do this. It will take the rolls array as its parameter and return a single- dimensional array of length 11, which your main() method will store in an array named totals. 6. Print the frequency array from step 5, properly labeled. You may do this in main() or write a method to do it. Yes; I know this is "inefficient." It is possible to construct the totals array at the same time that you create the rolls array. You could do everything in main()) without any other methods. However, I want you to practice passing and returning arrays to and from methods, so I decided to write the assignment this way. Sample output: Write a program named Dice.java that will do the following: 1. Ask the user how many times they wish to roll a pair of dice, from 1-999. Validate the input-keep asking until the number is in range. Write a method named getNRolls() to do this step. The method takes a scanner object as its parameter and returns the number of rolls the user desires. 2. Create a 6 x 6 array named rolls to hold the result of the rolls. 3. Simulate randomly rolling a pair of dice as many times as the user requested. As you roll the dice, count how many times each combination of dice was rolled. For example, if the first die is a 3 and the second die is 5, you will add one to the entry at rolls [2][4]. (If you generate numbers in the range 1-6, you will have to subtract one at appropriate places. If you generate numbers in the range 0-5, you don't need to do any subtraction). Write a method named rolldice() to do this step. It takes the number of rolls as its parameter and returns the two-dimensional array of rolls. 4. Print out the array, properly labeled, so that the numbers all line up. You can do this in main() or write a method to do it. 5. Go through the array you created in step 3 and figure out how many times the dice totaled 2, 3, 4. ... 12. Write a method called calcFrequencies ()) to do this. It will take the rolls array as its parameter and return a single- dimensional array of length 11, which your main() method will store in an array named totals. 6. Print the frequency array from step 5, properly labeled. You may do this in main() or write a method to do it. Yes; I know this is "inefficient." It is possible to construct the totals array at the same time that you create the rolls array. You could do everything in main()) without any other methods. However, I want you to practice passing and returning arrays to and from methods, so I decided to write the assignment this way. Sample output:
Expert Answer:
Answer rating: 100% (QA)
Dicejava import javautilRandom import javautilScanner public class Dice method to input the number o... View the full answer
Related Book For
Principles Of Information Security
ISBN: 9780357506431
7th Edition
Authors: Michael E. Whitman, Herbert J. Mattord
Posted Date:
Students also viewed these programming questions
-
9. Determine the next three terms of the sequence. Explain your reasoning. (4 marks) a. 1 2 3 4 2'5'8'11 b. 1, -8, 27, -64, 125......... 10. A population of rabbits if left unchecked will triple...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Randy, Inc., can issue 3-month commercial paper with a face value of $1,500,000 for $1,450,000. Transaction costs will be $1,500. The effective annualized percentage cost of the financing, based on a...
-
A right triangle is formed in the first quadrant by the x- and y-axes and a line through the point (2, 1) (see figure). Write the area A of the triangle as a function of x, and determine the domain...
-
As we look at Google, Facebook and Amazon, all three have potentials for a diversification into the realm of facial recognition. What are the potential benefits? Do the chances of consumer...
-
Describe the conditions under which non-monetary items designated in a foreign currency are subsequently remeasured under AASB 121/IAS 21?
-
American International Automotive Industries (AIAI) manufactures engine, transmission, and chassis parts for manufacturers and repair companies in the United States, South America, Canada, Mexico,...
-
17. A concave mirror produces a real image 10mm tall, of an object 2.5mm tall placed at 5cm from the mirror. Calculate focal length of the mirror and the position of the image. 18. An object is...
-
Problem 3 addressed the cross-sectional variation in the number of financial analysts who follow a company. In that problem, company size and debt-to-equity ratios were the independent variables. You...
-
Which of the following is true of the baby boomer generation? They lead lives shaped mainly by globalization. They are more questioning and entrepreneurial than the other generations. They give the...
-
What are some ideas for your social media strategy and how you will engage the mainstream media for an communication and advocacy for addressing the opioid crisis particularly the fentanyl overdose...
-
Match the following CSBs Question 4 options: but you must still report this income until the bond matures or you cash it in. report the amount shown on the T5 slips. until you cash it in. 1. Interest...
-
Provide the relevant AS/NZ Standard for the following PPE items: PPE item: AS/NZ Standard: 1.Gloves 2.Eyewear 3.Gowns 4.Masks
-
1. What are the prime goals of leadership development? 2. What role does a trend in healthcare professional supply play in the process of job analysis?
-
write a argumentative essay making a claim or claims going against the benefits of a healthy lifestyle community is really all about self care. the argument will include support from at least two of...
-
Assume that on January 1, year 1, ABC Incorporated issued 6,400 stock options with an estimated value of $5 per option. Each option entitles the owner to purchase one share of ABC stock for $35 a...
-
The following information is available for Partin Company: Sales $598,000 Sales Returns and Allowances 20,000 Cost of Goods Sold 398,000 Selling Expense 69,000 Administrative Expense 25,000 Interest...
-
An effective information security governance program requires a(n) ________ review. a. Periodic b. Constant c. Consistent d. Annual
-
Analyze components that make up security as a program and the professionals who are tasked with maintaining it within an organization.
-
Compare and contrast the differences between a CISO and CSO. Depending on the organization, the CISOs position may be combined with physical security responsibilities or may even report to a security...
-
Has the U.S. economy experienced inflation or deflation during recent recessions? Explain.
-
Inflation is soaring and employment is beginning to show sustained improvement. The unemployment rate is 6 percent, compared to its 3.5 percent rate prepandemic. The CPI grew 5.4 percent in June, and...
-
Explain how the Feds doubling of the monetarybase and government bailouts might influencethe short-run and long-run Phillips curves.Will the influence come fromchanges in the expected inflation rate,...
Study smarter with the SolutionInn App