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 Creating the MVP Storing Guesses

Problem with jshell. I open my game.java file and it says attempted to use class Game which cant be instanciat

class Game { private String answer;

public Game(String answer) { this.answer = answer; hits = ""; misses = ""; }

public boolean applyGuess(char letter) { boolean isHit = answer.indexOf(letter) != -1; if (isHit) { hits+= letter; } else { misses += letter; } return isHit; }

}

I feel as if I'm failing to do something with jshell. it says this error jshell> Game game = new Game("treehouse");
| attempted to use class Game which cannot be instanciated or its methods i nvoked until variable hits, and variable misses are declared

Pedro Araya
Pedro Araya
1,912 Points

Can you show us your code? You can either send us a snapshot of your workspace (Little icon in the upper right hand corner when you have your code open) .

Pedro Araya
Pedro Araya
1,912 Points

You missed the ints: hits and answer variables.

Pedro Araya
Pedro Araya
1,912 Points

Mark, try pasting this in the Game.java (It could help you):

class Game{
  private String answer;
  private String hits;
  private String misses;

  public Game(String answer) {
  this.answer = answer;
    hits = "";
    misses = "";
  }
  public boolean applyGuess(char letter) {
  boolean isHit = answer.indexOf(letter) != -1;
  if (isHit) {
   hits += letter;
  }else {
    misses += letter;
    }
  return isHit; 
    }
  }