import cse1030.Die; import java.util.Collections; import java.util.List; import java.util.ArrayList; public class Lab01D { public static void main(String[] args) { final int N = 5; // Create a list of N dice to roll List dice = new ArrayList(); for (int i = 0; i < N; i++) { dice.add(new Die()); } final int TRIALS = 1000000; int numberFullHouse = 0; for (int trial = 0; trial < TRIALS; trial++) { for (Die d : dice) { d.roll(); } // Sorting makes checking for a full house much easier! Collections.sort(dice); // A full house can only occur if the sorted dice have one of the // two configurations: // // X-X-Y-Y-Y // // or // // X-X-X-Y-Y // // where X and Y indicate arbitrary dice values. int first = dice.get(0).getValue(); int second = dice.get(1).getValue(); int third = dice.get(2).getValue(); int fourth = dice.get(3).getValue(); int fifth = dice.get(4).getValue(); boolean isFullHouse = (first == second && third == fifth) || (first == third && fourth == fifth); if (isFullHouse) { numberFullHouse++; } } System.out.printf("%.6f%n", (double) numberFullHouse / TRIALS); } }