import java.util.Scanner; /* DiceGame.java ** Java application that plays a silly game with a pair of dice, which are ** simulated using an instance of the PairOfDice class. ** The game has two phases. In the first, a pair of dice is rolled until ** such time as both a 7 and an 11 have occurred. In phase two, the dice are ** rolled until a result "equivalent" to the one that ended phase 1 occurs. ** ** A dice roll has a [[k][m]] result if the first die shows k pips and the ** second one shows m pips. Dice roll results [[k][m]] and [[p][q]] are ** said to be equivalent if either they are identical (i.e., k=p and m=q) ** or if they would be identical if one pair were swapped (i.e., k=q and m=p). ** ** An integer "seed" value must be provided to the program, for the purpose ** of pseudo-random number generation (used in implementing dice rolls). ** If a command line argument is provided, it is interpreted to be the ** seed. If not, the program prompts the user to enter one. ** ** Author: < STUDENT's NAME > ** Collaborators: ... ** Known Defects: ... */ public class DiceGame { 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]); } // < CODE MISSING > } /* Prints the given prompt and returns the response given at ** the keyboard. This is repeated until such time as the ** response can be interpreted to be an integer. */ private static int readInt(String prompt) { Scanner keyboard = new Scanner(System.in); int result = 0; // arbitrary initialization boolean finished = false; do { System.out.print(prompt); try { String response = keyboard.nextLine().trim(); result = Integer.parseInt(response); finished = true; } catch (Exception e) { System.out.println("Invalid response; try again.\n"); } } while (!finished); return result; } }