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 trialSohaib Rashid
627 PointsI used the same format as the prior video, but I am still stuck
If someone can assist, it would help me a lot! Happy coding!
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 getTitleCount()
String progress;
for (char tile: mHand.toCharArray()) {
char display = "-";
if (mHand.indexof(tile) >= 0) {
display = tile;
}
progress += display;
return progress;
}
}
1 Answer
Rebecca Bompiani
16,996 PointsHi Sohaib-
The basic logic for the challenge is as follows:
"For each char in mHand, if the tile matches the char, add one to the counter"
Try:
public int getTileCount(char tile) { //this method should return an int, because it will give you the number of times a letter shows up
int counter = 0; // initialize the counter at 0
for (char letter : mHand.toCharArray()) { //push all the characters in mHand to an array of characters, letter
if (letter==tile) { //loop through the chars, checking to see if the chars from the hand match the selected letter
counter ++; //if the char matches the letter selected, add one to the count
}
}
return counter; //return the count
}
Sohaib Rashid
627 PointsSohaib Rashid
627 PointsYou simplified it so much! Thank you for your help, i sure hope I can simplify and think as intelligent as you do! Happy Coding!!!!