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

Brad Pizzimenti
Brad Pizzimenti
14,640 Points

20 errors... after adding these changes can't find symbols for any of my methods.

Not sure how prompter seems to be missing all methods of mGame. Is there something in my code that decoupled prompter from game 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) {
      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: Try to solve: %s\n", 
                      mGame.getRemainingTries(),
                      mGame.getCurrentProgress());
  }
}
Brad Pizzimenti
Brad Pizzimenti
14,640 Points
           ^                                                                                                                                                 
./Game.java:38: error: variable letter is already defined in method validateGuess(char)                                                                      
    for (char letter : mAnswer.toCharArray()) {                                                                                                              
              ^                                                                                                                                              
./Game.java:46: error: incompatible types: String cannot be converted to char                                                                                
    return progress;                                                                                                                                         
           ^                                                                                                                                                 
./Game.java:50: error: incompatible types: possible lossy conversion from int to char                                                                        
    return MAX_MISSES - mMisses.length();                                                                                                                    
                      ^                                                                                                                                      
./Prompter.java:11: error: cannot find symbol                                                                                                                
    while (mGame.getRemainingTries() > 0) {                                                                                                                  
                ^                                                                                                                                            
  symbol:   method getRemainingTries()                                                                                                                       
  location: variable mGame of type Game                                                                                                                      
./Prompter.java:25: error: cannot find symbol                                                                                                                
        isHit =  mGame.applyGuess(guess);                                                                                                                    
                      ^                                                                                                                                      
  symbol:   method applyGuess(char)                                                                                                                          
  location: variable mGame of type Game                                                                                                                      
./Prompter.java:40: error: cannot find symbol                                                                                                                
                      mGame.getRemainingTries(),                                                                                                             
                           ^                                                                                                                                 
  symbol:   method getRemainingTries()                                                                                                                       
  location: variable mGame of type Game                                                                                                                      
./Prompter.java:41: error: cannot find symbol                                                                                                                
                      mGame.getCurrentProgress());                                                                                                           
                           ^                                                                                                                                 
  symbol:   method getCurrentProgress()                                                                                                                      
  location: variable mGame of type Game                                                                                                                      
20 errors     

3 Answers

Brad Pizzimenti
Brad Pizzimenti
14,640 Points

Found it! Looks like I was missing a close } at the end of my validateGuess() method.

I exported the text into Atom and once in there I could see that all of my methods further down had goofy syntax highlighting.

Oh syntax highlighting! I rely on it too much to know what's wrong!

Henning Bang Halvorsen
Henning Bang Halvorsen
16,239 Points

Just a little something... In your contructor, try to indent mGame = game; It seems you can't access the game object, so I guess something is wrong when you assign game to mGame.

Brad Pizzimenti
Brad Pizzimenti
14,640 Points

Hrm... Didn't help. I don't think java cares about white space (either horizontal or vertical). Thanks for the suggestion though.