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 trialAyokunle Awosoga
2,459 PointsPlease, what am I missing ("getTileCount") ????
I followed the exact steps as instructed but it keeps saying "Did i forget to use a method getTileCount that accepts char". Checked other answers on the forum and they kept introducing "Integer". Is that the only way to do 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 String getTileCount(){
String count = "";
for (char tile: mHand.toCharArray()) {
char display = '-';
if (mHand.indexOf(tile) >= 0) {
display = tile;
}
count += display;
}
return count;
}
}
1 Answer
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey Ayokunle,
What this challenge is asking you to do is create a method that returns an int and accepts a char as a parameter, you are supposed to loop through the entire mHand and if a tile matches the argument passed ie, you passed this method searching for the char a, and two a's are found in the tile, the count of two should be returned, the following code below should work.
public int getTileCount(char tile) {
int count = 0;
for (char letter : mHand.toCharArray()) {
if (tile == letter) {
count ++;
}
}
return count;
}
Let me know if you'd like me to try to explain something further and I'll see what I can do.