Problem3. The following is a short snippet of code that simulates rolling a 6-sided dice 100...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Problem3. The following is a short snippet of code that simulates rolling a 6-sided dice 100 times. There is an equal chance of rolling any digit from 1 to 6. public static void printDiceRolls(Random randGenerator) { for(int i=0; i<100; i++) { } } System.out.println(randGenerator.nextInt(6)+1); } public static void main(String[] args) Random r = new Random(); print DiceRolls(r); Create your own class, Loaded Dice, that is derived from Random. The constructor for Loaded Dice needs to only invoke Random's constructor. Override the public int nextInt(int num) method so that with a 80% chance, your new method always returns the largest number possible (num-1), and with 20% chance it returns what Random's nextInt method would return. Test your class by replacing the main method with the following: Loaded Dice myDice = new LoadedDice(); printDiceRolls(myDice); You do not need to change the printDiceRolls method even though it takes a parameter of type Random. Polymorphism tells Java to invoke Loaded Dice's nextInt() method instead of Random's nextInt() method. Problem3. The following is a short snippet of code that simulates rolling a 6-sided dice 100 times. There is an equal chance of rolling any digit from 1 to 6. public static void printDiceRolls(Random randGenerator) { for(int i=0; i<100; i++) { } } System.out.println(randGenerator.nextInt(6)+1); } public static void main(String[] args) Random r = new Random(); print DiceRolls(r); Create your own class, Loaded Dice, that is derived from Random. The constructor for Loaded Dice needs to only invoke Random's constructor. Override the public int nextInt(int num) method so that with a 80% chance, your new method always returns the largest number possible (num-1), and with 20% chance it returns what Random's nextInt method would return. Test your class by replacing the main method with the following: Loaded Dice myDice = new LoadedDice(); printDiceRolls(myDice); You do not need to change the printDiceRolls method even though it takes a parameter of type Random. Polymorphism tells Java to invoke Loaded Dice's nextInt() method instead of Random's nextInt() method. Problem3. The following is a short snippet of code that simulates rolling a 6-sided dice 100 times. There is an equal chance of rolling any digit from 1 to 6. public static void printDiceRolls(Random randGenerator) { for(int i=0; i<100; i++) { } } System.out.println(randGenerator.nextInt(6)+1); } public static void main(String[] args) Random r = new Random(); print DiceRolls(r); Create your own class, Loaded Dice, that is derived from Random. The constructor for Loaded Dice needs to only invoke Random's constructor. Override the public int nextInt(int num) method so that with a 80% chance, your new method always returns the largest number possible (num-1), and with 20% chance it returns what Random's nextInt method would return. Test your class by replacing the main method with the following: Loaded Dice myDice = new LoadedDice(); printDiceRolls(myDice); You do not need to change the printDiceRolls method even though it takes a parameter of type Random. Polymorphism tells Java to invoke Loaded Dice's nextInt() method instead of Random's nextInt() method. Problem3. The following is a short snippet of code that simulates rolling a 6-sided dice 100 times. There is an equal chance of rolling any digit from 1 to 6. public static void printDiceRolls(Random randGenerator) { for(int i=0; i<100; i++) { } } System.out.println(randGenerator.nextInt(6)+1); } public static void main(String[] args) Random r = new Random(); print DiceRolls(r); Create your own class, Loaded Dice, that is derived from Random. The constructor for Loaded Dice needs to only invoke Random's constructor. Override the public int nextInt(int num) method so that with a 80% chance, your new method always returns the largest number possible (num-1), and with 20% chance it returns what Random's nextInt method would return. Test your class by replacing the main method with the following: Loaded Dice myDice = new LoadedDice(); printDiceRolls(myDice); You do not need to change the printDiceRolls method even though it takes a parameter of type Random. Polymorphism tells Java to invoke Loaded Dice's nextInt() method instead of Random's nextInt() method.
Expert Answer:
Answer rating: 100% (QA)
The implementation of the LoadedDice class that extends Random and overrides the nextInt method to i... View the full answer
Related Book For
Accounting Principles Part 1
ISBN: 978-1118306789
6th Canadian edition
Authors: Jerry J. Weygandt, Donald E. Kieso, Paul D. Kimmel, Barbara Trenholm, Valerie Kinnear, Joan E. Barlow
Posted Date:
Students also viewed these programming questions
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
KYC's stock price can go up by 15 percent every year, or down by 10 percent. Both outcomes are equally likely. The risk free rate is 5 percent, and the current stock price of KYC is 100. (a) Price a...
-
(a) Let k be any real number and a < 1. Show that the function (1+x)k has the following power series representation (1 + x) = (h)a = 1+ kx + ? -x + k(k-1) 2! n=0 The above series is called the...
-
If a spring is stretched so far that it is permanently deformed, its force is no longer conservative. Why?
-
The 2004 movie documentary, The Corporation, argues that the corporation has become the dominant institution in American life, exceeding the influence of both religion and government. One result is...
-
Barbara Vigil, Chief Justice, New Mexico Supreme Court Ken Badilla bought a pair of Brahma brand work boots from Wal-Mart on October 19, 2003. The boots packaging had these express descriptions: iron...
-
You have been assigned to the first audit of the Chicago Company for the year ending March 31, 2011. Accounts receivable were confirmed on December 31, 2010, and at that date the receivables...
-
Why does the probability in this maximization problem become theta hat? Suppose we try to implement this social choice function. Assume that the buyers are expected utility maximizers. We now ask: If...
-
Go to the Webinars worksheet. DeShawn wants to determine the number of webinars the company can hold on Tuesdays and Thursdays to make the highest weekly profit without interfering with...
-
39. The critical angle of glass is 41. Which of the following will result in total internal reflection? a) 44 b) 40 c) 38 d) 20.5 40. Myopia is: a) A clouding of the lens b) Farsightedness c)...
-
Advise Roger as to any action he can take in discharging his tax liability.
-
OVERVIEW The ABC Humble Corporation is a trading company which also... OVERVIEW The ABC Humble Corporation is a trading company which also involves in rental business as its secondary business...
-
You are given the following spot rates of return $1 = 6.00% S2 = 6.75% S3 = 7.33% S4= 8.00% Calculate the one-year implied forward rate for the third year f(1,2).
-
Early theories that geography can influence a nation s economic policies and its economic growth rates date back to whom?
-
Charlie, Delta, and Echo are equal shareholders in CDE Corp., which has no E&P because it has been an S corporation since its inception. In Year 10, the corporation made pro rata non-liquidating...
-
d. (Optional) Prepare a system flowchart of a redesigned computer-based system that resolves the control weaknesses that you identified. Explain your solution. Wholesale customer orders are mailed,...
-
Use the following data to answer the next two (2) questions: Product 1 Product 2 Product 3 Direct Material Cost $25,000 $30,000 $35,000 Direct Labor Cost $30,000 $40,000 $50,000 Direct Labor Hours...
-
Sanjeet argues that no special internal controls are required for electronic funds transfer (EFT) cash receipts because employees are not handling cash or cheques. Is Sanjeet correct? Explain.
-
Home Goods Retail Company has the following merchandise account balances at its September 30 year end: Cost of goods sold.$125,000.Sales..............$218,750 Freight out1,900.Sales...
-
In the All About You feature, you learned about inventory theft and a relatively new technology to help prevent theft . You have recently accepted a part-time sales position at a clothing store...
-
A diploid organism has a total of 14 chromosomes and about 20,000 genes per haploid genome. Approximately how many genes are in each linkage group?
-
By conducting testcrosses, researchers have found that the sweet pea plant has seven linkage groups. How many chromosomes would you expect to find in leaf cells of sweet pea plants?
-
Describe the unique features of ascomycetes that facilitate genetic analysis of these fungi.
Study smarter with the SolutionInn App