Due by the end of Tuesday, October 24
Your first task is to create a method for rolling the standard, six-sided dice. The program uses the same code on two separate lines (both with the comment Activity 1). Replace those formulas with calls to a method named rollD6. The method takes no arguments, and returns a random number in the range of 1 to 6.
I've already created the javadoc comment for you. Place the definition of this method directly below the javadoc comment for it. (Note that there are three javadoc comments provided -- the other two are for activities 2 and 3.)
Run your program again and make sure it performs exactly as before. For example, you might get
Next you will complete part two of the program. There are many different kinds of dice besides just the regular six-sided kind. There are four-sided, eight-sided, ten-sided, twelve-sided and twenty-sided. And you can use two ten-sided dice to simulate rolling a 100-sided die.
Create a method named rollD (under the appropriate javadoc comment) for rolling a multi-sided die. This method is given the number of sides on the die (which can be any integer number at all) and simulates rolling a die with that many sides.
Don't worry if the number of sides doesn't make sense. It's OK if they ask for a seven-sided die or a twenty-three-sided die. It's even OK if they ask for a one-sided die, a zero-sided die, or a minus-nineteen-sided die. Computer scientists have a saying: "Garbage in; garbage out." That means that if they ask for something stupid, we'll give them something stupid back. But if they ask for something reasonable, we'll give them what they want.
Find the place in main where d1 and d2 are assigned the value 0 (the lines marked with the comment Activity 2). Change them so that d1 is set to the result of rolling a 10-sided die, and d2 to the result of rolling a 100-sided die (just as it says in the output). For example, you might get
Our last activity with this program is to write a method that rolls multiple dice. The method is called rollMany and it's given the number of dice to roll and how many sides are on each die. It uses a loop to simulate rolling that many dice with that many sides, and returns the sum of all those rolls For example, if it were given 2 and 6, it would simulate rolling two six-sided dice, and it might return 2, or 7, or 12 -- whatever those two dice added up to.
Find the place in main where sum is assigned the value 0 (the line marked with the comment Activity 3). Change it so that sum is set to the result of rolling the dice requested by the user (just as it says in the output).
Test your method by running the program several times, checking that the sum is appropriate to the number and type of dice rolled. (The sum must be at least the same as the number of dice, and at most the number of dice times the number of sides. It'll usually be around half-way in between those extremes, tho'.) For example, you might get
Submit this/these files:
You will be graded on the following: