ann

One APCSA FRQ ### Content - Class HiddenWord - Class Driver

Class HiddenWord

public class HiddenWord{
    String word;
    public HiddenWord(String w){
        word=w;
    }
    public String getHint(String str){
        String r="";
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)==word.charAt(i)){
               r=r+str.charAt(i);
            }
            else{
                boolean flag=false;
                for(int j=0;j<str.length();j++){
                    if(i==j){
                        continue;
                    }
                    if(str.charAt(i)==word.charAt(j)){
                        flag=true;
                        break;
                    }
                }
                r+=flag?"+":"*";
            }
        }
        return r;
    }
}

Class Driver

import java.util.*;
public class driver{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        System.out.println("Enter: ");
        String h=scan.next();
        HiddenWord p=new HiddenWord(h);
        while(true){
            String g=scan.next();
            System.out.println(p.getHint(g));
            if(p.getHint(g).equals(h)){
                break;
            }
        }
    }
}