Write the complete HiddenWord class, including any necessary instance variables, its constructor, and the method, getHint, described above. You may assume that the length of the guess is the same as the length of the hidden word.

import java.util.Scanner;
public class HiddenWord {
    private String word;
    public HiddenWord(String hiddenWord){
        word = hiddenWord;
    }
    public String getHint(String attempt){
        String hint = "";
        for(int i=0; i<attempt.length();i++){
            if(attempt.charAt(i)==word.charAt(i)){
                hint+=attempt.charAt(i);
            }
            else if(word.indexOf(attempt.charAt(i))!=-1){
                hint+="+";
            }
            else{
                hint+="*";
            }
        }
        return hint;
    }
    public static void main(String[] args) {
        HiddenWord puzzle = new HiddenWord("HARPS");
        Scanner scan = new Scanner(System.in);
        boolean playing = true;
        while (playing){
            System.out.println("Guess a 5 letter word");
            String attempt = scan.nextLine();
            System.out.println(attempt);
            String hint = puzzle.getHint(attempt);
            System.out.println("Hint: "+hint);
            if(hint.equals(puzzle.word)){
                System.out.println("You win");
                playing=false;
            }
        }
    }
}
HiddenWord.main(null);
Guess a 5 letter word
AAAAA
Hint: +A+++
Guess a 5 letter word
HELLO
Hint: H****
Guess a 5 letter word
HEART
Hint: H*++*
Guess a 5 letter word
HARMS
Hint: HAR*S
Guess a 5 letter word
HARPS
Hint: HARPS
You win

In this FRQ question, it regards the topic of Classes and Method and Control Structures. It tests our knowledge of creating a class for the hidden word game. It has a constructor to initialize the word and a method to convert the player’s guess to make a hint for the player. By using the class and methods, it ensures the game is structured which is very useful in programming. Also, this is tests our knowledge on Method and Control structures because we had to compare and modify strings. We had to iterate through the strings to find matching characters to do the challenge.