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 Validating and Normalizing User Input

Andre Kucharzyk
Andre Kucharzyk
4,479 Points

System.out.print... problem

So here is the snapshot of my workspaces: https://w.trhou.se/nzxiv6oj5q

Problem is that even though in my Main class I have:

        if (prompter.promptForGuess()) {
            System.out.println("You've guessed");
        } else {
            System.out.println("You've not guessed");
        }

and in Prompter class I have"

public void displayProgress() {
    System.out.printf("You have %d tries left to solve: %s%n",
            game.getRemainingTries(),
            game.getCurrentProgress());
}

when I run the code and I type in letter and press enter(doesn't matter if the letter is in the answer), console shows:

Enter a letter:
g Enter a letter:

meaning, that after "g" it doesn't display the text "You've guessed"/"You've not guessed", neither it displays the progress text "You have %d tries left to solve: %s%n".

Please, help me.

1 Answer

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

You're actually asking the prompter to ask for a letter 2 times before displaying the progress

prompter.promptForGuess(); // here you're asking for a letter the first time

if (prompter.promptForGuess()) {  // here you're asking the prompter for a letter again
    System.out.println("You've guessed");
} else {
    System.out.println("You've not guessed");
}
Andre Kucharzyk
Andre Kucharzyk
4,479 Points

Thank you so much for the answer :) That's so obvious now, I fail to understand how could I not see it before.