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 Current Progress

Christopher Stutler
Christopher Stutler
3,080 Points

My Code is All kinds of messed up

Getting numerous errors

public class Hangman {

    public static void main(String[] args) {
        // Enter amazing code here:
      Game game =  new Game("treehouse");
      Prompter prompter = new Prompter(game);
      Prompter.displayProgress();
      boolean isHit = prompter.promptForGuess();
      if(isHit) {
        System.out.println("We Got A Hit!");                    
    } else {
      System.out.println("Whoops that was a miss");
    }
    prompter.dispalyProgress();                       

}
} 
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);
  }

  public void displayProgress(){
    System.out.printf("Try to Solve: %s\n", mGame.getCurrentProgress());
}

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

  public String getCurrentProgress() {
    String progress = "";
    for (char letter: mAnswer.toCharArray()) {
      char display = '-';
      if (mHits.indexof(letter) >=0) {
        display = letter;
  }
        progress += display; 
    }



}
}

The Console shows six errors including ./Prompter.java:1: error: cannot find symbol
import java.io.console;

which makes no sense since It's verbatim what is written in the video.

Also, this whole process would be so much easier if the code was included in the teachers notes. It's hard to compare by going back and forth in the video.

Thanks

2 Answers

Jeff Hill
Jeff Hill
751 Points

Capitalize "Console";

Simon Coates
Simon Coates
28,694 Points

1) unsure but maybe import import java.io.Console; 2) prompter.dispalyProgress(); is a spelling mistake