Outlab 3: Petals Around the Rose
Due: Friday 26 February at 6 pm
Purpose
Gain experience with decision statements, reading/using user
input, and generating random numbers.
Partners
This is an individual assignment, though collaboration (not
solution sharing) is allowed.
Problem Statement
Petals Around the Rose is a puzzle that asks you to determine the
"number of petals around the rose", given five dice.
Read about the problem here
and here.
Play the simulator in the link until you understand how the game
works and can guess correctly every time.
In this assignment, you will be building your own Petals simulator
that rolls dice (generates random numbers for die values: 1-6).
You will also ask the user what their guess for the number of
petals is and compare their answer to the correct answer.
Assignment
- Create an Outlab3 project and paste this code into a class called Driver.
- Carefully review the Driver, as it contains clues about the
structure of the rest of the program.
- Supply the missing PetalsGame class as well as the methods
that the Driver indicates you need.
- If your implementation is correct, your output should look
similar to this. Your output won't be
identical, since it depends on user menu selections and the
random die values.
- DO NOT PROCEED FURTHER UNTIL YOU HAVE THE ABOVE WORKING
PERFECTLY!
- Once everything above is working perfectly, modify the Driver
so that the user has a third menu option, 3. Guess. If
this option is selected, the user should be presented the dice
values and then prompted for a guess. This guess should then be
checked for correctness and an appropriate message printed.
Appropriate output for this section would be this.
Hints
- Before you write code, write down (pencil and paper) the
equation for calculating to correct number of petals for ONE die
(can you translate what you wrote to a Java method?).
- Your first task is to get the PetalsGame working with the
Driver as is, do not modify the Driver for this first step.
- Work one method at a time: Is rollDice() working correctly?
Now is printDice() working correctly?...
- Think carefully about what methods you need. You may want
methods in the PetalsGame class that I have not told you about.
- Once you are ready to start handling user input (after the "DO
NOT PROCEED" step above), you do not need to modify PetalsGame
anymore.
Submission
By Friday 26 February at 6 pm, submit the files Driver.java
and PetalsGame.java into the appropriate D2L dropbox folder.
DO NOT SUBMIT .class files!
Grading - 20 points
- 3 points - rollDice() uses Math.random() each time it is
called.
- 3 points - calculateAllPetals() is correct and efficient
(around 7 lines of code).
- 5 points - The new menu works correctly and user input is
evaluated appropriately.
- 4 points - The output looks good and is formatted as in the
example.
- 5 points - Good programming principles are followed (comments,
minimal unnecessary code, efficient solution,...).