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 Delivering the MVP Wrapping Up

i did great doing the hangman game, but cant run it on Eclipse..?

Hello there,

I finished the hangman game, now what I am trying to do is, to do the game in Eclipse, i did everything the same, but when i run Hangman.java, i only get:

Usage: java Hangman<answer> answer is required

How am I supposed to run this in console so that I can put the answer just like when I run in Workspace with: java Hangman "word"?

++ How can i use REPL localy in Eclipse?

Thank you very much.

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Try adding to the arguments tab of the Run Configuration.

Hope that helps!

Yes, that worked, thank you very much for your answer.

What else i really want to do and try on eclipse if it is possible, how can i make it when I run the Hangman.java, I want the user to enter the word so the others can guess it, not with arguments.

Thank you so much again Craig.

To allow the user to input the answer, you would want to create a prompter method for the answer in the Prompter.java file and a setter method in Game.java. Something like

// Prompter.java
public String promptForAnswer() {
  Scanner scanner = new Scanner(System.in);
  System.out.print("Enter a word to guess:   ");
  answer = scanner.nextLine();
}

// Game.java
public void setAnswer() {
  answer = prompter.promptForAnswer();
}

Remove this line from the Game constructor:

this.answer = answer.toLowerCase();

And then rewrite a portion of Hangman.java. Replace the main method with this:

public static void main(String[] args) {
    // Your incredible code goes here...

    Game game = new Game();
    Prompter prompter = new Prompter(game);
    game.setAnswer();
    while (game.getRemainingTries() > 0 && !game.isWon()) {
      prompter.displayProgress();
      prompter.promptForGuess();
    }
    prompter.displayOutcome();
  }

Handling an invalid answer is an exercise for the reader.