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

Tom Schinler
Tom Schinler
21,052 Points

Workspaces is giving me an error.

I am following along in Workspaces, and have verified that my code matches the video, but when I try to run, I get this error:

./Prompter.java:13: error: incompatible types: String cannot be converted to boolean
String guessAsString = console.readline("Enter a Letter: ");
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

here is the Prompter.java

import java.io.Console;

public  class Prompter {
  private Game mGame;


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

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

here is 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);
      boolean isHit = prompter.promptForGuess();
      if (isHit) {
        System.out.println("We got a hit!");
      } else {
        System.out.println("Nope");
      }
    }

}

and Game.java

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) {
    boolean isHit = mAnswer.indexOf(letter) >=0;
    if (isHit) {
      mHits += letter;
    } else {
      mMisses += letter;
    }
    return isHit;
  }

}

Please help as this is killing me slowly.

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

readline should be readLine. It's case sensitive. That's a pretty weird error. Sorry for the stump. Keep at it!

Tom Schinler
Tom Schinler
21,052 Points

Thanks a bunch Craig!