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
Matthew Francis
6,967 PointsSuper Newbie - What is wrong with my code?
Right when I added "mGame.hitOrMisss(userLetter);" in the Prompter.java, the whole compiler does not work (it says cannot find symbol), any ideas why?
//In file called HelloWorld.java
public class HelloWorld{
public static void main(String []args){
String secretWord = "treehouse";
Game nGame = new Game(secretWord);
Prompter nPrompter = new Prompter(nGame);
nPrompter.enterMsg();
}
}
//In another file called Game.java
public class Game{
private String mAnswer;
private String mHits;
private String mMisses;
public Game(String secretWord){
mAnswer = secretWord;
mHits = "";
mMisses = "";
}
public void hitOrMiss(String userLetter){
if(mAnswer.indexOf(userLetter) >= 0){
mHits+=userLetter;
}
else{
mMisses+=userLetter;
}
}
}
//In another file called Prompter.java
import java.io.Console;
public class Prompter{
public String userLetter;
private Game mGame;
public Prompter(Game newGame){
mGame = newGame;
}
public void enterMsg(){
Console console = System.console();
userLetter = console.readLine("Enter a letter: ");
mGame.hitOrMisss(userLetter);
}
}
1 Answer
Jonathan Petersen
45,721 PointsIn the Prompter class, you are calling the hitOrMiss method on the mGame object. You have an extra 's' you have
mGame.hitOrMisss(userLetter);
and it should be
mGame.hitOrMiss(userLetter);
Don't feel bad. Something like this happens all of the time. An IDE would catch this.