/** * Simulates a gaming wheel. * @author Jeff Raab */ public class GamingWheel { /** Prizes on this wheel. */ protected Prize[] prizes = null; /** * Constructs a wheel with the given prize values. * @param values prize values for the wheel */ public GamingWheel(int[] values) { if (values == null) { throw new RuntimeException("Array is null"); } if (values.length < 2) { throw new RuntimeException("Not enough values"); } prizes = new Prize[values.length]; for (int i = 0; i < prizes.length; i++) { prizes[i] = new Prize(values[i]); } } /** * Spins this the given number of clicks. * @param num number of clicks to spin this */ public void spin(int num) { for (int i = 0; i < num; i++) { rotateRight(); } } /** Rotates the prizes in the array one index to the right. */ private void rotateRight() { Prize temp = prizes[prizes.length - 1]; for (int i = prizes.length - 1; i > 0; i--) { prizes[i] = prizes[i - 1]; } prizes[0] = temp; } /** Returns the currently selected prize. */ public Prize currentPrize() { return prizes[0]; } /** Returns the number of prizes on this. */ public int prizeCount() { return prizes.length; } }