Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following methods for WordGuess.java Jgrasp preferred. return true pub

ID: 3910801 • Letter: W

Question

Write the following methods for WordGuess.java Jgrasp preferred. return true public static String updatelserword (char guess, string wserword, string thosord) Returns a userWord with all occurrenc user word was h" and the user guessed e: the returr ring would be ."e."h". public static String datelwesses(string guesses, char guess Updates the list of guesses with the current guess. The update should only add the guess if it does not already exist in the list. The new guess must be placed at the end of the existing list of guesses. For example, if guesses were "tabg and the current guess were , this method would return "tabg public static String displayöserond(String usererd) Returns a String that is the userWord with spaces between each letter and each " replaced with an : For example, if the userWord is "fe" this method would return fe..Note that there is no space before the T and after the last' es of " corresponding to the current guess replaced with that guess. For example, if the word was "fetch' and the public static string displayuesses int strikes, string e Returns a String in the form-Strikes: %dtGuesses %s with the list of guesses separated by spaces. For example if there were 3 strikes and guesses were "bed", this method would return"Strikes: 31tGuesses: bcd'

Explanation / Answer

public static String updateUserWord(char guess, String userWord, String theWord){

    String s = "";
    for (int i = 0; i<theWord.length(); i++){
         if (userWord.charAt(i) == guess))
            s = s + guess;
         else
            s = s + userWord.charAt(i);
    }
    return s;
}

public static String updateGuesses(String guesses, char guess){
    
    int found = 0;
   
    for (int i = 0; i<guesses.length(); i++){
        if (guess == guesses.charAt(i)){
           found = 1;
           break;
        }
    
    }
    if (found == 0){
       guesses = guesses + guess;
    }
    return guesses;
}

public static String displayUserWord(String userWord){
    
   
   
    String s = "";
    for (int i = 0; i<userWord.length(); i++){
       if (userWord.charAt(i) != '*'){
          if (i < userWord.length() -1){
             s = s + userWord.charAt(i) + " ";
          }
          else {
             s = s + userWord.charAt(i);
          }
       }
       else {
          if (i < userWord.length() -1){
             s = s + "_" + " ";
          }
          else {
             s = s + "_";
          }

       }     
    }
    return s;
}

public static String displayGuesses(int strikes, String guesses){

     
     String s = "Strikes: %" + Integer.toString(d) + " Guesses: ";
     for (int i = 0; i<guesses.length(); i++){
         if (i < guesses.length()-1)
             s = s + guesses.charAt(i) + " ";
         else
             s = s + guesses.charAt(i);
     }
     return s;
}