FRQ QUESTION 2
public class HiddenWord {
private String hiddenWord;
public HiddenWord(String word) {
hiddenWord = word;
}
public String getHint(String guess) {
StringBuilder hint = new StringBuilder();
for (int i = 0; i < guess.length(); i++) {
char guessChar = guess.charAt(i);
char hiddenChar = hiddenWord.charAt(i);
if (guessChar == hiddenChar) {
hint.append(hiddenChar);
} else if (hiddenWord.indexOf(guessChar) != -1) {
hint.append("+");
} else {
hint.append("*");
}
}
return hint.toString();
}
}
- The Java class HiddenWord represents a simple game where a hidden word is compared to a guessed word, and a hint is generated based on the match between the guessed word and the hidden word.