Di
or NumberCube
int
parameter and sets that to the number of sides. return 1 + (int)(sides*Math.random() ) ;
toString()
method so it returns a string reporting the number facing up and how many sides it has, for example: D20 is showing 13
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."); } }
Here is a link to a graphical way to make Dice.