Logic of the main Method
Line 26 in main
calls rollDice
, which picks two random values from 1 to 6, displays the values of the first die, the second die and their sum, and returns the sum. Method main
next enters the switch
statement (lines 29–45), which uses the sumOfDice
value from line 26 to determine whether the game has been won or lost, or should continue with another roll. The values that result in a win or loss on the first roll are declared as public static final int
constants in lines 14–18. The identifier names use casino parlance for these sums. These constants, like enum
constants, are declared by convention with all capital letters, to make them stand out in the program. Lines 31–34 determine whether the player won on the first ...
Get Android™ How to Program, Second 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.