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 trialSarfaraj Alam
14,074 PointsCode Challenge : Strings And Chars
public class ScrabblePlayer { private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
mHand += tile; // Adds the tile to the hand of the player
}
public boolean hasTile(char tile) {
boolean hasHand;
if(hasHand){
return true;
} else{
return false;
}
}
what is wrong in this code? it says reached end of the file while parsing
public class ScrabblePlayer {
private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
mHand += tile; // Adds the tile to the hand of the player
}
public boolean hasTile(char tile) {
boolean hasHand;
if(hasHand){
return true;
} else{
return false;
}
}
3 Answers
Derek Markman
16,291 PointsIt's because you're missing a closing curly brace for the class.
public class ScrabblePlayer {
private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
mHand += tile;
}
public boolean hasTile(char tile) {
boolean hasHand;
if(hasHand) {
return true;
} else {
return false;
} //closing curly brace for the if-else statement
} //closing curly brace for the hasTile method
} //closing curly brace for the class
Sarfaraj Alam
14,074 PointsStill This is not working
Derek Markman
16,291 PointsYou're gonna have to be more specific, are you still getting the same error as before?
Sarfaraj Alam
14,074 PointsNo but it says ./ScrabblePlayer.java:19: error: cannot find symbol if(hasHand){ ^ symbol: variable hasHand location: class ScrabblePlayer ./ScrabblePlayer.java:19: error: illegal start of type if(hasHand){ ^ 2 errors
Derek Markman
16,291 PointsI believe you're getting that error because in your if statement's boolean expression. Simply saying if(hasHand) is not a valid Boolean expression. Especially since hasHand isn't assigned to any value, it has just been declared. So, by saying, if(hasHand) is not testing anything.