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...


write a code in java


The following is a short snippet of code that simulates rolling a 6-sided dice 100 times. There is an equal chance of<br>rolling any digit from 1 to 6.<br>public static void printDiceRolls(Random randGenerator)<br>{<br>for ( int i = 0; i< 100; i++)<br>{<br>System.out.println(randGenerator.nextInt(6) + 1);<br>public static void main(String[] args)<br>Random randGenerator = new Random(:<br>printDiceRolls(randGenerator);<br>}<br>Create your own class, LoadedDice, that is derived from Random. The constructor for LoadedDice needs to only<br>invoke Random 's constructor. Override the public int nextInt(int num) method so that with a 50% chance, your<br>new method always returns the largest number possible (i.e., num – 1), and with a 50% chance, it returns what<br>Random's nextInt method would return.<br>Test your class by replacing the main method with the following:<br>LoadedDice myDice = new LoadedDice();<br>printDiceRolls(myDice); You do not need to change the printDiceRolls method even though it takes a parameter of<br>type Random. Polymorphism tells Java to invoke LoadedDice 's nextInt() method instead of Random 's nextInt()<br>method.<br>

Extracted text: 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="" randgenerator="new" random(:="" printdicerolls(randgenerator);="" }="" create="" your="" own="" class,="" loadeddice,="" that="" is="" derived="" from="" random.="" the="" constructor="" for="" loadeddice="" needs="" to="" only="" invoke="" random="" 's="" constructor.="" override="" the="" public="" int="" nextint(int="" num)="" method="" so="" that="" with="" a="" 50%="" chance,="" your="" new="" method="" always="" returns="" the="" largest="" number="" possible="" (i.e.,="" num="" –="" 1),="" and="" with="" a="" 50%="" chance,="" it="" returns="" what="" random's="" nextint="" method="" would="" return.="" test="" your="" class="" by="" replacing="" the="" main="" method="" with="" the="" following:="" loadeddice="" 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="" loadeddice="" 's="" nextint()="" method="" instead="" of="" random="" 's="" nextint()="">

Jun 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here