public class DiceTally { int minimum; int numberOfDice = 2; int numberOfSides = 6; int minimumRoll = numberOfDice; int numberofCombinations = numberOfDice * numberOfSides - minimumRoll + 1; int[] tallies = new int[numberofCombinations]; public DiceTally(int min) { minimum = min; } public void tallyAndReport() { clearTallies(); doTallies(); doReport(); } private void clearTallies() { for (int i = 0; i < numberofCombinations; ++i) { tallies[i] = 0; } } private void doTallies() { while (!isDoneTallying()) { doTally(); } } private boolean isDoneTallying() { return getMinimumTally() >= minimum; } private int getMinimumTally() { int min = Integer.MAX_VALUE; for (int i = 0; i < numberofCombinations; ++i) { min = Math.min(min, tallies[i]); } return min; } private void doTally() { incrementTally(convertDiceRollToIndex(rollDice())); } private int rollDice() { int sum = 0; for (int i = 0; i < numberOfDice; ++i) { sum += rollDie(); } return sum; } private int rollDie() { return 1 + (int) (Math.random() * numberOfSides); } private int convertDiceRollToIndex(int roll) { return roll - minimumRoll; } private void incrementTally(int tally) { tallies[tally]++; } private void doReport() { for (int i = 0; i < numberofCombinations; ++i) { reportCombination(i); } } private void reportCombination(int n) { System.out.println(n + minimumRoll + " " + tallies[n]); } }