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 trialAndrew Mitchell
2,739 PointsI need help don't know what i'm doing wrong
Here is my code can someone tell me what i'm doing worng and how to fix it
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 += tile;
}
public boolean hasTile(char tile) {
return mHand.indexOf(tile) > -1;
}
public int getTileCount(char someTile) {
int tileCount = 0;
for (char tile : mHand.toCharArray()) {
if (mHand.indexOf(tile) >= 0) {
tileCount++;
}
}
return tileCount;
}
}
3 Answers
Craig Dennis
Treehouse Teacherif (tile == someTile) {
Craig Dennis
Treehouse TeacherSeems to me that mHand.indexOf(tile)
will always be there.
HINT: Hmmm...maybe you should try comparing it to the tile being passed in through the method? It's currently named someTile
.
Hope it helps!
Andrew Mitchell
2,739 PointsOk i kinda of see what your saying but i don't fully understand, could you explain again and give a code example (when i see code examples along with an explanation it helps)
Andrew Mitchell
2,739 PointsPlease help me
Andrew Mitchell
2,739 PointsAndrew Mitchell
2,739 PointsThanks that worked :)