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 Remaining Tries

Dylan Carter
Dylan Carter
4,780 Points

cant solve these errors

I get 2 errors cannot find symbol for the prompter class lines 13 and 14 " ./prompter.java:13 error cannot find symbol while (mGame.getRemainingTries > 0 { ^ symbol: variable getRemainingTries location variable mGame of type Game

./prompter.java:14: error: cannot find symbol displayProgress(); ^ symbol: method displayProgress() location: class Prompter "

My code:

----BEGIN GAME CLASS----

game.java
public class Game {
  public static final int MAX_MISSES = 7;
  private String mAnswer;
  private String mHits;
  private String mMisses;

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

  public boolean applyGuess(char letter) {
    boolean isHit = mAnswer.indexOf(letter) >= 0;
    if (isHit) {

      mHits += letter;
    } else {
    mMisses += letter;
    }
   return isHit;
    }

  public String getCurrentProgress() {
   String progress = "";
    for (char letter: mAnswer.toCharArray()) {
     char display = '-';
      if (mHits.indexOf(letter) >= 0) {
       display = letter;
      }
      progress += display;
    }
    return progress;
  }

    public int getRemainingTries() {
  return MAX_MISSES - mMisses.length();
  }


  }

------BEGIN PROMPTER CLASS-----

prompter.java
import java.io.Console; 

public class Prompter {
 private Game mGame;



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

  public void play() {
  while (mGame.getRemainingTries > 0) {
   displayProgess();
    promptForGuess();
  }
  }

  public boolean promptForGuess() {
  Console console = System.console();
    String guessAsString = console.readLine("Enter a letter:  ");
  char guess = guessAsString.charAt(0);
    return mGame.applyGuess(guess);
  }


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

----BEGIN HANGMAN CLASS----

hangman.java
public class Hangman {

    public static void main(String[] args) {
        // Enter amazing code here:
    Game game = new Game("treehouse");


  Prompter prompter = new Prompter(game);
      prompter.play();
}
}

I'm sorry I don't know how to make it show the black background code block so if you could tell me that it would be helpful as well.

Ken Alger
Ken Alger
Treehouse Teacher

Edited for markdown.

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Dylan;

For the issue of displayProgress, make sure you are spelling that correctly in your Prompter.java code. And, I think you want to be using getRemainingTries(), not getRemainingTries. :wink:

Post back if you are still stuck.

Happy coding,
Ken

Dylan Carter
Dylan Carter
4,780 Points

omg thank you, I was so focused on trying to figure out in the syntax I messed up I didn't even think it would have been a simple misspelling wow.

Ken Alger
Ken Alger
Treehouse Teacher

Happens all the time. Please it was resolved.

:thumbsup: