Question: I'm trying to figure out why my code isn't compiling. Any feedback is greatly appreciate it. Thanks public class WordGuess { /** * Returns a

I'm trying to figure out why my code isn't compiling. Any feedback is greatly appreciate it. Thanks

public class WordGuess {

/** * Returns a string of stars representing the word */ public static String makeUserWord(String theWord) { StringBuffer result = new StringBuffer(); for (int index = 0 ; index < theWord.length() ; index++) { result.append('*'); } return result.toString(); } /** * * TEsts to see if char appears inside a given word * */ public static boolean isInWord(char guess, String theWord){ for (int index = 0 ; index < theWord.length() ; index++) { if ( guess == theWord.charAt(index) ) { return true; } } return false; } public static String updateUserWord(char guess, String userWord, String theWord){ StringBuffer result = new StringBuffer(); for (int index = 0 ; index < userWord.length() ; index++) { if ( userWord.charAt(index) == '*' ) { // This positions was not guessed correctly before, so, test it now if ( theWord.chatAt(index) == guess) { // The guess is correct for this position result.append( guess ); } else { // The guess is INCORRECT for this position result.append( '*' ); } } else { //Already Figured before result.append( userWord.charAt(index) ); } } } public static String updateGuesses(String guesses, char guess){ boolean found = false; for (int index = 0 ; index < guesses.length() ; index++) { if (guesses.charAt(index) == guess) { found=true; break; // Because we found one, we break and don't check the remained of the String } } if ( !found ) { return guesses+guess; } else { return guesses; } } public static String displayUserWord(String userWord){ StringBuffer result = new StringBuffer();

for (int index = 0 ; index < userWord.length() ; index++) { if ( userWord.charAt(index) == '*') { result.append("_ "); } else { result.append( userWord.charAt(index) ); result.append( " " ); } } return result.toString().trim() ; } public static String displayGuesses(int strikes, String guesses){ String template = "Strikes: %d\tGuesses: %s"; StringBuffer result = new StringBuffer(); for (int index = 0 ; index < guesses.length() ; index++) { result.append( guesses.charAt(index) ); result.append( " " ); } return String.format(template, strikes, result.toString().trim() ); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!