/** * The Row class will keep the guess and the answer and the outcome for each try * * @author John Paxton * @version 1.0 */ public class Row { /** * The Row constructor initialzes the Guess and Answer objects * @author John Paxton * @version 1.0 * @param numberPegs is an int of the number of pegs */ Row (int numberPegs) { guess = new int [ numberPegs ]; answer = null; black = 0; white = 0; } /** * recordGuess will take an array of numbers and put them in the guess array * * @author John Paxton * @version 1.0 * @param colorsGuessed this int[] is the guess that the person made */ public void recordGuess ( int [] colorsGuessed ) { for (int i = 0; i < guess.length; i++) { guess[i] = colorsGuessed[i]; } } /** * This method will set the answer from another Answer * * @author John Paxton * @version 1.0 * @param answer this Answer is the actual answer that is being copied over * to the answer that with this object * @precondition the answer is not set * @postcondition answer is now set to the real answer */ public void setAnswer ( Answer answer ) { this.answer = answer; } /** * This method will score the guess with answer * * @author John Paxton * @version 1.0 * @precondition the black and white variables are not set * @postcondition the black and white variables are set */ public void scoreGuess() { black = 0; white = 0; answer.reset(); for (int i = 0; i < guess.length; i++) { if (guess[i] == answer.getPeg(i)) { black++; answer.setPegUsed(i); } } for (int i = 0; i < guess.length; i++) { if (guess[i] != answer.getPeg(i)) // logic error was here { for (int j = 0; j < guess.length; j++) { if ((guess[i] == answer.getPeg(j)) && (!answer.getPegUsed(j))) { white++; answer.setPegUsed(j); break; } } } } } /** * This print method will print out the number guess and the number of black * and whites * * @author John Paxton * @version 1.0 * */ public void print () { for (int i = 0; i < guess.length; i++) { System.out.print (guess[i] + " "); } System.out.println("Black: " + black + " White: " + white); } /** * This method will get the number of blacks * * @author Reid Roper and Nick Lamb * @version 1.0 * @return black this int is the number of set blacks */ public int getBlack() { return black; } private int [] guess; private int black; private int white; Answer answer; }