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

Paul Joiner
Paul Joiner
1,682 Points

An error with Prompter.java is preventing Hangman.java from compiling, but I'm following the video. Did I miss something

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);
  }
}
Paul Joiner
Paul Joiner
1,682 Points

When I go to compile Hangman.java I get the following error message: <p>./Prompter.java:10: error: missing method body, or declare abstract
public boolean promptForGuess(); {
^
./Prompter.java:14: error: return outside method
return mGame.applyGuess(guess);
^ </p>

3 Answers

It's a little hard to tell because you aren't providing us with your error or your hangman.java. My first question is, does your apply Guess method return a boolean?

EDIT: After review I found the error

public boolean promptForGuess(); {

You have a semicolon after your method which should not be there. Semicolons in java are used to end statements.

public boolean promptForGuess() {

Would be your proper format. Hope this helps Happy Coding!

Paul Joiner
Paul Joiner
1,682 Points
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("Whoops that was a miss");
    }
  }

}
Paul Joiner
Paul Joiner
1,682 Points

In game.java, my applyGuess method ends with the line return isHit;

Paul Joiner
Paul Joiner
1,682 Points

In game.java, my applyGuess method ends with the line return isHit;