/** * This Answer class will create the answer for the game * * @author John Paxton * @version 1.0 */ public class Answer { /** * This constructor will set the make the answer and flag arrays * * @author John Paxton * @version 1.0 * @param howManyPegs is how many pegs the game will use * @param howManyColors is how many colors the game will use * */ Answer (int howManyPegs, int howManyColors) { colors = howManyColors; answer = new int [ howManyPegs ]; flags = new boolean [ howManyPegs ]; } /** * This will make a random answer * * @author John Paxton * @version 1.0 * @precondition the answer array was empty * @postcondition the answer array was filled */ public void createAnswer () { for (int i = 0; i < answer.length; i++) { answer[i] = (int) (colors * Math.random()) + 1; } } /** * This method resets the flag array * * @author John Paxton * @version 1.0 * @precondition the flags array has both true and false * @postcondition the flags array is all false */ public void reset () { for (int i = 0; i < flags.length; i++) { flags[i] = false; } } /** * this getPeg method will get the peg by position * * @author John Paxton * @version 1.0 * @param position the position in the array to retrieve * @return answer[position] an int in the answer array */ public int getPeg (int position) { return answer[position]; } /** * Checks if a peg has been used in the scoring and sets the flags to tell you * * @author John Paxton * @version 1.0 * @param position the position in the flags array to check * @return flags[position] a boolean if the peg has been used yet */ public boolean getPegUsed (int position) { return flags[position]; } /** * This method will set a peg as beeing used * * @author John Paxton * @version 1.0 * @param posision the position of the peg that has been used * @precondition the postion in flags was set to false * @postcondition the position in flags was set to true */ public void setPegUsed (int position) { flags[position] = true; } /** * This method will print out the answer and what the flags were * this is for debugging * * @author John Paxton * @version 1.0 */ public void print () { for (int i = 0; i < answer.length; i++) { System.out.print ( answer[i] + " "); } System.out.println(); } private int colors; private int [] answer; private boolean [] flags; }