Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Creating the MVP Prompting for Guesses

Charles Harpke
Charles Harpke
33,986 Points

Error in the console.

Here is 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;
  }
}

Here is 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("Whoops that was a miss");
        } 
    }

}
Charles Harpke
Charles Harpke
33,986 Points

The error I receive in the console:

I get the following error(s) in my console: Console console = System.console(); ^ Symbol: class Console location: class Prompter 3 errors

Ken Alger
Ken Alger
Treehouse Teacher

Charles;

What error(s) are you getting?

Ken

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Charles;

You need to capitalize Console in your import statement in your Prompter.java file.

Ken

Charles Harpke
Charles Harpke
33,986 Points

The error in the console:

I get the following error(s) in my console: Console console = System.console(); ^ Symbol: class Console location: class Prompter 3 errors