Classes
- This FRQ was about comparing and finding the similarities between a secret word and a guessed word. This FRQ is basically the extremely popular game Wordle and I’m surprised it became as popular as it did being this simple. For this question, I had to go through a guessed word and give clues based on matching letters and if they’re in the hidden word. This was very challenging for me and I had to google a few things (such as the charAt function) to make the program much a lot simpler. By using Classes, I managed to finish the Wordle game.
Program
public class HiddenWord {
public String word;
public HiddenWord(String w) {
word = w;
}
public String getHint(String guess) {
String result = "";
for (int i = 0; i < guess.length(); i++) {
if (guess.charAt(i) == word.charAt(i))
result += "" + guess.charAt(i);
else if (word.indexOf(guess.charAt(i)) > -1)
result += "+";
else
result += "*";
}
return result;
}
public static void main(String[] args) {
HiddenWord puzzle = new HiddenWord("HARPS");
System.out.println(puzzle.getHint("AAAAA"));
System.out.println(puzzle.getHint("HELLO"));
System.out.println(puzzle.getHint("HEART"));
System.out.println(puzzle.getHint("HARMS"));
System.out.println(puzzle.getHint("HARPS"));
}
}
HiddenWord.main(null);
+A+++
H****
H*++*
HAR*S
HARPS