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 trialM G
2,833 PointsStuck on Challenge Task 2 Stage 3 Java Objects
Having issues with method "hasTile", I don't know what I am doing wrong, can somebody please help me with this.
public class ScrabblePlayer {
private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
// Adds the tile to the hand of the player
mHand = Character.toString(tile);
}
public boolean hasTile(char tile) {
boolean isHit = mHand.indexOf(tile) >= 0;
if (isHit) {
return true;
} else {
return false;
}
}
}
2 Answers
Craig Dennis
Treehouse TeacherYour addTile
method is wrong. It needs to append. I will fix that, whoops!
Your second method, hasTile
looks good. You could also just return the expression as it returns true or false.
Dane Parchment
Treehouse Moderator 11,077 PointsI haven't done this one before but it seems to me like your hasTile method is not actually returning anything we can fix this one of two ways:
public boolean hasTile(char tile) {
boolean isHit = mHand.indexOf(tile) >= 0;
if (isHit) {
return true;
}
return false;
}
Or......
public boolean hasTile(char tile) {
return mHand.indexOf(tile) >= 0;
}
M G
2,833 PointsThank you, I appreciate it.
M G
2,833 PointsM G
2,833 PointsI got it and fix it. Thank you!