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

I can not run my java code in workspaces.

I dont know what the proplem is, the console is not even throwing errors. Bsicaly i cant run my code but i can compile it, is the proplem with my code or the workspace.

here are all the files:

import java.io.Console;
public class Prompter {
 private Game mGame;

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

 public void play() {
  while(mGame.mMisses.length() >= mGame.getRemainningTries()) {
    displayProgress();
    promptForGuess();
  }
 }

 public boolean promptForGuess() {

  Console console = System.console();

  String guessAsString = console.readLine("Enter your guess: ");
  //the guess variable gets the first letter of the input that the user inters in the guessAsString variable.
  char guess = guessAsString.charAt(0);
  // finaly the promptForGuess() method returns  the character the user inserted and in the same time 
  return mGame.applyGuess(guess);

 }

  public void displayProgress() {
    System.out.printf("You have: %d tries left. right right right!:  %s\n", mGame.getRemainningTries() ,mGame.howManyRight());
  }

}
public class Game {
  public static final int MAX_MISSES = 7;
  private static String mAnswer;
  public static String mHits;
  public String mMisses; 
  private int mManyTimes;
  public char letter;

  public Game(String answer) {
    mAnswer = answer;
    mHits = "";
    mMisses = "";
  }



  public boolean applyGuess(char letter) {
   boolean isHit = mAnswer.indexOf(letter) >= 0;

   if (isHit) {
    mHits = mHits + letter;
    } else {
      mMisses = mMisses + letter;
   }

   return isHit;


  }
  public static String howManyRight() {
    String hitler = "";
    for (char letter: mAnswer.toCharArray()) {
      char display = '_';
      if(mHits.indexOf(letter) >= 0) {
        display = letter;
      }
      hitler = hitler + display;
    }
    return hitler;
  }

  public int getRemainningTries() {
    return MAX_MISSES - mMisses.length();
  }
}
Here is the main file:

```java 

import java.io.*;
public class Hangman {

    public static void main(String[] args) {
        // Enter amazing code here:
        Game game = new Game("treehouse");
        Prompter prompter = new Prompter(game);
        prompter.play();

    }
}