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
Marty scheid
1,589 PointsDelivering the MVP, Validation. Every time i compile my code i get this error cannot find symbol
Hello, I'm stuck i cannot solve this please help.
error message
javac Hangman.java
./Game.java:26: error: cannot find symbol
letter = validateLetter(letter);
^
symbol: method validateLetter(char)
location: class Game
1 error
Code
{public class Game {
private String mAnswer;
/// final means cannot be changed alcaps MAS_MISSES means constant\\\\\
public static final int MAX_MISSES =7;
private String mMisses;
private String mHits;
//constructor\\\
public Game(String answer) {
mAnswer = answer;
mHits = "";
mMisses = "";
}
// private method\\\
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;
}
///method\\\
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();
}
}
}
Thanks for the help!
2 Answers
Seth Kroger
56,416 PointsYou've called the method as validateLetter() but you've defined it as validateGuess();
Marty scheid
1,589 Pointspublic class Game {
private String mAnswer;
/// final means cannot be changed alcaps MAS_MISSES means constant\\\\\
public static final int MAX_MISSES =7;
private String mMisses;
private String mHits;
//constructor\\\
public Game(String answer) {
mAnswer = answer;
mHits = "";
mMisses = "";
}
// private method\\\
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;
}
///method\\\
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();
}
}
Marty scheid
1,589 PointsMarty scheid
1,589 PointsThank you for the fast response!!!