Answered step by step
Verified Expert Solution
Question
1 Approved Answer
11.9 LAB^: Loaded Dice (polymorphism) Write a class LoadedDice which is derived from java.util.Random. The constructors for LoadedDice should invoke the appropriate constructors for Random.
11.9 LAB^: Loaded Dice (polymorphism) Write a class LoadedDice which is derived from java.util.Random. The constructors for LoadedDice should invoke the appropriate constructors for Random. (Hint: use super) Override the public int nextInt(int num) method. The new method will return the highest number possible (i.e. num - 1) with a 50% chance. The other 50% of cases, a random within the range will be returned. Ex. If the input is: 6 the output is: 6 sided die, java.util. Random 2 5 5 1 2 1 3 3 2 2 5 6 3 2 1 4 3 1 6 6 4 5 6 5 4 2 5 1 5 5 5 2 3 4 3 3 4 5 3 2 6 1 6 6 2 3 4 6 3 5 1 1 6 5 2 6 6 5 2 5 5 4 3 1 5 1 2 4 2 6 1 3 5 6 3 6 1 3 2 2 5 5 3 6 5 4 1 1 4 3 3 5 1 2 6 6 6 1 25 6 sided die, LoadedDice 6 6 1 6 3 2 6 6 3 1 3 6 6 4 6 6 6 5 5 5 6 6 3 6 5 2 1 6 6 4 6 5 1 5 6 5 5 4 6 6 1 6 2 6 6 6 6 6 6 6 6 5 3 5 1 4 3 6 2 6 6 1 5 6 6 6 6 6 3 6 1 5 3 6 6 6 3 6 6 1 6 4 6 3 6 6 5 6 4 6 6 6 6 6 6 4 6 6 5 4. Note: The Driver is using an intial seed to ensure the test cases always return the same result. File is marked as read only Current file: DiceDriver.java 1 import java.util.Scanner; 2 import java.util. Random; 3 4 public class DiceDriver { 5 public static void main(String[] args) { 6 Scanner scnr = new Scanner(System.in); 7 8 int numSides - scnr.nextInt(); 9 10 System.out.println(numSides + sided die, java.util. Random"); 11 Random randGen = new Random(100); 12 printDiceRolls(randGen, numSides); 13 14 System.out.println(); 15 System.out.println(numSides + " sided die, LoadedDice"); 16 LoadedDice myDice = new LoadedDice(100); 17 printDiceRolls(myDice, numSides); 18 } 19 20 public static void printDiceRolls(Random randGenerator, int numSides) { 21 int cand = 2: 10 11 12 13 14 15 System.out.println(numsides + sided die, java.util. Random"); Random randGen = new Random(100); printDiceRolls(randGen, numSides); System.out.println(); System.out.println(numSides + " sided die, LoadedDice"); LoadedDice myDice = new LoadedDice(100); printDiceRolls(myDice, numSides); 16 17 18 } NNNNN 19 20 21 22 23 public static void printDiceRolls (Random randGenerator, int numSides) { int rand = 0; for (int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started