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


Given this

public boolean promptForGuess() {
        Scanner s = new Scanner(System.in);
        boolean isHit = false;
        boolean isValidInput = false;

        do {
            System.out.print("Enter a letter: ");
            String input = s.nextLine();
            char letter = input.charAt(0);

            try {
                isHit = game.applyGuess(letter);
                isValidInput = true;
            } catch (IllegalArgumentException iae) {
        } while (!isValidInput);

        return isHit;

Because of this line of code, I believe

char letter = input.charAt(0);

If a pass to the constructor a word like this "Wrong".
Whether I type any of these "R, O, N, G" the toLowerCase() command will work. Not so with "W" if I type "w" it will count as a miss.

Oh, it turns out that it only works if the passed answer is all in lower case

1 Answer

J llama
J llama
12,631 Points

what a great job by treehouse here.....lets make a 13 min video