number_cube
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
number_cube [2019/09/13 13:25] – frchris | number_cube [2019/09/16 14:32] (current) – frchris | ||
---|---|---|---|
Line 3: | Line 3: | ||
- Make have 2 instance variables: the total number of sides, and the side currently facing up | - Make have 2 instance variables: the total number of sides, and the side currently facing up | ||
- Make a default Constructor with no parameters that initializes the instance variables | - Make a default Constructor with no parameters that initializes the instance variables | ||
+ | - Make another Constructor that takes an '' | ||
- Make a roll method that randomly changes the current side facing up. It should return an int <code java> return 1 + (int)(sides*Math.random() ) ;</ | - Make a roll method that randomly changes the current side facing up. It should return an int <code java> return 1 + (int)(sides*Math.random() ) ;</ | ||
- Override the default '' | - Override the default '' | ||
+ | - Make a NumberCubeTester that create a 12 sides die and a 6 sided die, and the makes a loop: | ||
+ | |||
+ | <code java> | ||
+ | |||
+ | public class NumberCubeTester | ||
+ | { | ||
+ | public static void main ( String[] | ||
+ | { | ||
+ | Scanner kb = new Scanner(System.in); | ||
+ | String input = ""; | ||
+ | System.out.println(" | ||
+ | // make 2 new number cubes | ||
+ | do | ||
+ | { | ||
+ | // roll the cubes and return the sum of the 2 dice | ||
+ | | ||
+ | System.out.println(" | ||
+ | input = kb.nextLine(); | ||
+ | } | ||
+ | while ( ! input.equalsIgnoreCase(" | ||
+ | System.out.println(" | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Here is a link to a graphical way to make [[https:// |
number_cube.1568395543.txt.gz · Last modified: 2019/09/13 13:25 by frchris