CS112: In-class Exercise 10 Multiple constructors Grab the BlueJ project rolling-dice-10 from public \ Yuen(CS) \cs112BlueJ in the lab. When reading the following, pay attention to which class is being discussed. 1. Modify the Die class to have the capability of specifying how many sides the die has. • Add a new instance variable, numberOfSides. • Add an additional constructor that takes a parameter that specifies the number of sides. • Modify the method roll() so that the number of sides is taken into consideration. • Test. ◊ Make a new 20-sided Die object using the new constructor. ◊ Roll and see what you get (use inspect or getValue()). ◊ Test several times. ◊ Make a new 8-sided Die object using the new constructor and test again. 2. Now modify the Dice class to allow specifying what kind of dice. • No new instance variables are needed! • Add an additional constructor that takes a parameter that specifies the number of sides on each dice. • Test.
This is the end of the preview.
access the rest of the document.