/** Driver.java -- Let's roll a pair of die a bunch of times to see how often * a desired sum comes up. We can do this to check an expected "empirical * probablility". For example, we can test to see if you can really roll * a 7 one-sixth of the time. */ import java.util.Scanner; public class Driver { public static void main(String [] args) { Scanner kbd = new Scanner(System.in); // Ask for the necessary input... System.out.printf("How many sides on a die? "); int numSides = kbd.nextInt(); System.out.printf("What sum are you looking for? "); int desiredSum = kbd.nextInt(); System.out.print("How many tries would you like? "); int numRolls = kbd.nextInt(); // Create a die object so we can roll dice. Die die = new Die(numSides); // Now let's roll the dice in a loop. // Note that "++" means to add 1 to a variable. int count = 0; int trial = 0; while (trial < numRolls) { int firstValue = die.roll(); int secondValue = die.roll(); int sum = firstValue + secondValue; System.out.printf("%d + %d = %d\n", firstValue, secondValue, sum); if (sum == desiredSum) ++count; ++trial; } System.out.printf("Your desired sum of %d came up %d times.\n", desiredSum, count); } }