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 Validation

I'm having a hard time trying to solve these 2 errors

./Prompter.java:11: error: cannot find symbol
while (mGame.getRemainingTries() > 0) {
^
symbol: method getRemainingTries()
location: variable mGame of type Game
./Prompter.java:36: error: cannot find symbol
mGame.getRemainingTries(),
^
symbol: method getRemainingTries()
location: variable mGame of type Game
2 errors

TeacherAssistant.java
import java.io.Console;


public class Prompter {
 private Game mGame;

  public Prompter(Game game) {
    game = mGame;
}
  public void play() {
   while (mGame.getRemainingTries() > 0) {
    displayProgress();
     promptForGuess();
   }
  }
  public boolean promptForGuess() {
   Console console = System.console(); 
    boolean isHit = false;
    boolean isValidGuess = false;
    while (!isValidGuess) {
      String guessAsString = console.readLine("Enter a letter: ");
      char guess = guessAsString.charAt(0);
      try {
        isHit = mGame.applyGuess(guess);
        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 this: %s\n", 
                     mGame.getRemainingTries(),
                     mGame.getCurrentProgress());
  }
}
Jeff Wilton
Jeff Wilton
16,646 Points

Where does the class Game come from on your 3rd line? Is that something you need to import?

Stayl T
Stayl T
968 Points

You are assigning value to game instead of mGame under the constructor! Doing this will not assign the game logic to mGame which you are using in the entire program!

Correction:

mGame = game;

instead of

game = mGame;

Hope it helps.

I'm still getting the same errors with even with the correction mGame = game on mGame.getRemainingTries() method. am i importing the Game class wrong?

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

I believe you either made a typo in naming getRemainingTries() in Game.java or, haven't written it (or forgot to save Game.java after writing it) before compiling. Either way, the issue is really in Game.java, not Prompter.java

LOL thanks!!! i totally forgot about that