public class Dice { public Dice() { } public Dice(int[] values) { for (int i : values) add(i); } public int getCount(int die) { assert 1 <= die && die <= 6; return counts[die - 1]; } public void add(int die) { assert 1 <= die && die <= 6; counts[die - 1]++; } public void addAll(Dice other) { for (int i = 0; i < 6; i++) { counts[i] += other.counts[i]; } } public boolean remove(int die) { if (getCount(die) > 0) { counts[die - 1]--; return true; } else return false; } public void removeAll(Dice other) { for (int i = 0; i < 6; i++) { counts[i] = Math.max(0, counts[i] - other.counts[i]); } } public boolean contains(Dice other) { for (int i = 0; i < 6; i++) { if (counts[i] < - other.counts[i]) return false; } return true; } public void empty() { for (int i = 0; i < 6; i++) { counts[i] = 0; } } public int size() { int result = 0; for (int i = 1; i <= 6; i++) result += getCount(i); return result; } public String toString() { String result = ""; for (int i = 1; i <= 6; i++) for (int j = 1; j <= getCount(i); j++) result += i; return result; } private int[] counts = new int[6]; }