Java Bootcamp Resources, launch
Print the rules to the user:
>> Let's play Rolling Java. Type anything to start.
>> Great, here are the rules:\n
>> - If you roll a 6, the game stops.
>> - If you roll a 4, nothing happens.
>> - Otherwise, you get 1 point.\n
>> You must collect at least 3 points to win. Enter anything to roll:
while loop that runs forever.
Place your second
scan.nextLine() from Task 1 as the first line in your loop. Print
hey in your loop's second line.
After testing your code, remove the
/** * Function name: rollDice * @return randomNumber (int) * * Inside the function: * - return a random number between one and six. */
During each run, call
rollDice() and store the value in
diceRoll. Print each dice roll:
You rolled a <diceRoll>..
Whenever the user rolls a 6:
End of game.
- stop the game.
Whenever the user rolls a 4:
Zero points. Keep rolling.
When the user rolls anything else:
scorevariable by 1
One point. Keep rolling.
After the game ends, check the user's points. If the score is greater than or equal to 3, print:
Wow, that's lucky. You win!
Tough luck, you lose :(
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.