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 trialThomas Katalenas
11,033 PointsApplyGuess()?
https://teamtreehouse.com/library/java-objects/creating-the-mvp/prompting-for-guesses
I understand everything except for the applyGuess() method, where did it come from I dont see applyGuess anywhere else in the code
3 Answers
Uriah Nevins
1,121 PointsSo the applyGuess method is actually in the game.java file, which he does not open in that video. but I happen to have it in my workspace from that course.
public boolean applyGuess(char letter){
letter = validateGuess(letter);
boolean isHit = mAnswer.indexOf(letter) >= 0;
if(isHit){
mHits += letter;
}else{
mMisses += letter;
}
return isHit;
}
so what that is doing is it's checking two things : whether it is a valid guess, and whether it is a hit or miss. You might not remember why you made that method, but that is why. So to sum it up, your appyGuess(); method is checking whether it is a valid guess, then applying it to either the hits or the misses. Hope that helps :)
-Your fellow beginner, Uriah Nevins
jcorum
71,830 PointsIt's in the Game.java file in the workspace:
public boolean applyGuess(char letter) {
boolean isHit = mAnswer.indexOf(letter) >= 0;
if (isHit) {
mHits += letter;
} else {
mMisses += letter;
}
return isHit;
}
Thomas Katalenas
11,033 Pointsah i see it now..woopsii
Uriah Nevins
1,121 PointsUriah Nevins
1,121 PointsJcorum, you beat me to it while I was typing. :-)