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 trialJordan Ernst
5,121 Pointsi understand absolutely nothing of this question.
i continue getting the incorrect answer here and my count is always 8. i am so confused when we change to an in value and accept a parameter to me it is far off from the video. can someone show me what to do it would be greatly appreciated
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;
}
}
Grigorij Schleifer
10,365 PointsHey Jordan,
glad I could help :)
See you in the forum :)
1 Answer
Grigorij Schleifer
10,365 PointsHi Jordan,
allow me to comment the code of this challenge:
We create a method that proofs and counts how many tiles are inside mHand. Not only if there is a tile inside mHand.
public int getTileCount(char tile) {
// so you need to add a getTileCount method, it is public and returns an integer
// the returned integer will represent the number of tiles inside mHand
// to proof a specific char inside mHand you need to give that chat as parameter to the method
// so the new method accepts a char "tile" and proofs whether tile is inside mHand
// and if true, the counter will increased by one
int count = 0;
// to increase a counter, we first create one
for (char letter : mHand.toCharArray()) {
// to compare chars inside a String mHand you need to "convert" String mHand in an array of chars using toCharArray()
// inside the for loop you want to compare every char from the mHand-array with your argument "tile"
if (letter == tile) {
// if a char from mHandArray equals to the argument char
// increment the count
count += 1;
}
}
return count;
// return the number of tiles inside mHand
}
Does it make sense?
Grigorij
Jordan Ernst
5,121 Pointsperfect explanation! the obvious if statement and i totally overlooked it thanks so much i'll be asking you for help in the future!
Jordan Ernst
5,121 PointsJordan Ernst
5,121 Pointsi am not sure if i am supposed to add an if statement or what. i feel that it would have a condition all though i don't understand what i am checking for