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 (Retired) Delivering the MVP Validation

Nikolay Egov
Nikolay Egov
96 Points

I keep getting strange errors

Hello. I really need your help on this one. I used to get 9 errors but I managed to clear most . I checked the code with the tutorial, searched in Google but the errors returned just don't make sense. I'm stuck with this:

./Game.java:18: error: bad operand types for binary operator '||'
if (mMisses.indexOf(letter) >= 0 || mHits.indexOf(letter)) >=0) {
^
first type: boolean
second type: int
./Game.java:25: error: cannot find symbol
letter = validateLetter(letter);
^
symbol: method validateLetter(char)
location: class Game
4 errors

Here is my Game.java.com:

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

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

private char validateGuess (char letter) { if(! Character.isLetter(letter)) { throw new IllegalArgumentException("A letter is required"); } letter = Character.toLowerCase(letter); if (mMisses.indexOf(letter) >= 0 || mHits.indexOf(letter)) >=0) { throw new IllegalArgumentException(letter + " has already been guessed"); } return letter; }

public boolean applyGuess(char letter) { letter = validateLetter(letter); boolean isHit = mAnswer.indexOf(letter) >= 0; if(isHit) { mHits += letter; } else { mMisses += letter; } return isHit; }

public String getCurrentProgress() { String progress = ""; for (char letter: mAnswer.toCharArray()) { char display = '-'; if (mHits.indexOf(letter) >= 0) { display = letter; } progress += display; } return progress; }

public int getRemainingTries() { return MAX_MISSES - mMisses.length(); } }

Nikolay Egov
Nikolay Egov
96 Points

Not sure why the format is so messed up. Everything appears correctly when I try to copy/paste or edit the post...

Nikolay Egov
Nikolay Egov
96 Points

OK, please ignore. Everything is working now. Not Sure what the problem was but it got away after I rewrote one of the if statements.

1 Answer

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

You accidentally had an extra right parenthesis, closing your statement early.

Nikolay Egov
Nikolay Egov
96 Points

Oh, yes, I can see it now. Thanks a lot!