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) Creating the MVP Prompting for Guesses

Brian Maimone
Brian Maimone
Courses Plus Student 1,644 Points

One Hangman error, would appreciate help.

cannot find symbol, boolean isHit = prompter.promptForGuess(); symbol: method promptForGuess() ; location: variable prompter of type Prompter. We're calling a method on an object which I'm not clear about. My code below:

public class Hangman {

    public static void main(String[] args) {
        // Enter amazing code here:
        Game game = new Game("treehouse");
        Prompter prompter = new Prompter(game); //pass game object ,created above, into Prompter; now Prompter knows about game logic
        boolean isHit = prompter.promptForGuess(); //call method on prompter object
        if (isHit) {
          System.out.println("We got a hit"); }
        else {
          System.out.println("Whooops that was a miss"); }


import java.io.Console;

public class Prompter {// object to do i/o
  private Game mGame; 

  public Prompter(Game game) {//constructor takes Game object called game
    mGame = game; //set mGame to what was passed in (game)

  public boolean prompForGuess() { // returns T/F
    Console console = System.console();// Console is a class importing from java.io
    String guessAsString = console.readLine("Enter a letter: ");
    char guess = guessAsString.charAt(0);
    return mGame.applyGuess(guess);//call applyGuess method, pass in guess(1st char from string)return T/F
public class Game {
  private String mAnswer;
  private String mHits;
  private String mMisses;

  public Game(String answer) {
   mAnswer = answer;
   mHits = "";
   mMisses = "";


  public boolean applyGuess(char letter) {//method to apply a guess towards the puzzle, takes a letter, returns T if hit, F  for miss
    boolean isHit = mAnswer.indexOf(letter) >= 0; //boolean value knows whether or not guess is good, mAnswer = Treehouse
    if (isHit) {
      mHits += letter; //update hit count
    } else {
      mMisses += letter;

    return isHit; 


2 Answers

Craig Dennis
Craig Dennis
Treehouse Teacher

Hmmm.... prompForGuess seems to be missing something. Dot your i's and cross your t's.

Craig Dennis
Craig Dennis
Treehouse Teacher

No problem...years of making mistakes, makes those easier to find ;)