import java.util.Scanner; /* Java application that is for the purpose of illustrating how to use an ** instance of the PairOfDice class to simulate the rolling of a pair of dice. ** ** One integer input is needed. If a command line argument is provided, ** that is taken to be the input value. Otherwise, the user is prompted ** to enter one. The input is used to seed the pseudo-random number ** generators that produce pseudo-random dice roll results. ** ** Author: R. McCloskey ** Last Modified: November 2, 2022 */ public class DiceApp { public static void main(String[] args) { int seed; if (args.length == 0) { seed = readInt("Enter an integer-valued seed: "); } else { seed = Integer.parseInt(args[0]); } // Create a new pair of dice, using the just-established seed (for // pseudo-random number generation). PairOfDice dice = new PairOfDice(seed); // Now roll the dice several times, each time reporting the result. for (int i=1; i<=10; i=i+1) { dice.roll(); // Report the result of the roll: System.out.print("Dice roll result is " + dice.toString()); System.out.print("; Sum is " + dice.getSum()); System.out.print(" First die: " + dice.getNumPips(1)); System.out.print(", Second die: " + dice.getNumPips(2)); System.out.println(); } System.out.println("Goodbye."); } /* Prints the given string and returns the response provided at the ** keyboard, which must be interpretable as an integer. */ private static int readInt(String prompt) { System.out.print(prompt); Scanner keyboard = new Scanner(System.in); return keyboard.nextInt(); } }