InClassExercise10

InClassExercise10 - CS112: In-class Exercise 10 Multiple...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
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.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.
Ask a homework question - tutors are online