User Tools

Site Tools


number_cube

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
number_cube [2019/09/13 13:25] frchrisnumber_cube [2019/09/13 13:40] 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 ''int'' parameter and sets that to the number of sides. 
   - 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() ) ;</code>   - 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() ) ;</code>
   - Override the default ''toString()'' method so it returns a string reporting the number facing up and how many sides it has, for example: ''D20 is showing 13''   - Override the default ''toString()'' method so it returns a string reporting the number facing up and how many sides it has, for example: ''D20 is showing 13''
 +  - Make a NumberCubeTester that create a 12 sides die and a 6 sided die, and the makes a loop: 
 +
 +<code java>import java.util.Scanner;
 +
 +public class NumberCubeTester
 +{
 +    public static void main ( String[]  args )
 +    {
 +        Scanner kb = new Scanner(System.in);
 +        String input = "";
 +        System.out.println("Welcome to the Number Rolling Tester");
 +        // make 2 new number cubes
 +        do 
 +        {
 +            // roll the cubes and return the sum of the 2 dice
 +            
 +            System.out.println("Press return to roll, type Q to quit");
 +            input = kb.nextLine();
 +        }
 +        while ( ! input.equalsIgnoreCase("Q") );
 +        System.out.println("Thanks for testing this out.");
 +
 +    }
 +}
 +</code>
number_cube.txt · Last modified: 2019/09/16 14:32 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki