Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Delivering the MVP Determining if It Is Solved

Charles Harpke
Charles Harpke
33,986 Points

error in the prompter class.

I get the following error:

System.out.printf(Bummer the word was %s. :(\n",

symbol: class word location : class Prompter ./Prompter.java20: error:cannot find symbol m.Game.getAnswer());

symbol: method getAnswer() location: class Prompter 14 errors here is my code:

import java.io.Console;

public class Prompter {
  private Game mGame;

  public Prompter(Game game) {
    mGame = game;
  }

  public void play() {
    while (mGame.getRemainingTries() > 0 && !mGame.isSolved()) {
      displayProgress();
      promptForGuess();
    }
    if (m.Game.isSolved()) {
      System.out.printf("Congratulations you won with %d tries remaining.\n",
                       mGame.getRemainingTries());
    } else {
      System.out.printf(Bummer the word was %s.  :(\n",
                        mGame.getAnswer()); 
                        }                                        
  }

  public boolean promptForGuess() {
    Console console = System.console();
    boolean isHit = false;
    boolean isValidGuess = false;
    while (! isValidGuess) {
    String guessAsString = console.readLine("Enter a letter: ");
    try {
        isHit = mGame.applyGuess(guessAsString);
        isValidGuess = true;
      } catch (IllegalArgumentException iae) {
        console.printf("%s. Please try again.\n", iae.getMessage());
      }
    }    

    return isHit; 
  }
public void displayProgress() {
  System.out.printf("You have %d tries left to solve: %s\n",
                    mGame.getRemainingTries(),
                    mGame.getCurrentProgress());
}
}
Charles Harpke
Charles Harpke
33,986 Points
import java.io.Console;

public class Prompter {
  private Game mGame;

  public Prompter(Game game) {
    mGame = game;
  }

  public void play() {
    while (mGame.getRemainingTries() > 0 && !mGame.isSolved()) {
      displayProgress();
      promptForGuess();
    }
    if (mGame.isSolved()) {
      System.out.printf("Congratulations, you won with %d tries remaining. \n",
                        mGame.getRemainingTries());
    } else {
      System.out.printf("Bummer the word was %s.  :(\n",
                        mGame.getAnswer());
    }
  }  

  public boolean promptForGuess() {
    Console console = System.console();
    boolean isHit = false;
    boolean isValidGuess = false;
    while (! isValidGuess) {
      String guessAsString = console.readLine("Enter a letter: ");
      try {
        isHit = mGame.applyGuess(guessAsString);
        isValidGuess = true;
      } catch (IllegalArgumentException iae){
        console.printf("%s. Please try again.\n", iae.getMessage());
      }
    }
    return isHit;
  }

  public void displayProgress() {
    System.out.printf("You have %d tries left to solve: %s\n", 
                      mGame.getRemainingTries(),
                      mGame.getCurrentProgress());
  }
}

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Charles;

Did you get this solved with your second post and the addition of the other double quote?

Ken

Charles Harpke
Charles Harpke
33,986 Points

Yes...I see the code posted earlier...