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 trialRaiyan Rahman
Courses Plus Student 8,091 PointsJava Objects: Answer is not being accepted for Scrabble tile count code challenge.
Hello everyone, I've been trying to create a method that will give me a count of the number of times a tile appears in a given hand.
I believe the code if I've written is the correct answer to the question. However, the compiler is not accepting my answer.
Could some give me some pointers on where I could be going wrong?
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 tile) {
int count = 0;
//For each loop to count instances of tile.
for(char tileInHand : mHand.toCharArray()) {
if(tileInHand == tile) {
count += 1;
}
}
return count;
}
1 Answer
Jack Middlebrook
19,746 PointsIt looks like your problem is your public int getTileCount(char tile) is outside of the bracket that closes your scrabble player class. If you move the following code inside the last } you should be good:
public int getTileCount(char tile) {
int count = 0;
//For each loop to count instances of tile.
for(char tileInHand : mHand.toCharArray()) {
if(tileInHand == tile) {
count += 1;
}
}
return count;
}
Raiyan Rahman
Courses Plus Student 8,091 PointsRaiyan Rahman
Courses Plus Student 8,091 PointsOh now I see; I can't believe I missed that.
Thank you so much for your help.