... enables us to create one SecureRandom object that’s reused in each call to rollDice.

Method main’s Local Variables

The game is reasonably involved. The player may win or lose on the first roll, or may win or lose on any subsequent roll. Method main (lines 20–66) uses

  • local variable myPoint (line 21) to store the “point” if the player doesn’t win or lose on the first roll,

  • local variable gameStatus (line 22) to keep track of the overall game status and

  • local variable sumOfDice (line 24) to hold the most recent roll’s sum of the dice.

Variable myPoint is initialized to 0 to ensure that the application will compile. If you do not initialize myPoint, the compiler issues an error, because myPoint is not assigned a value in every case of the switch

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.