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 trialsachin gupta
2,553 Pointsneed some clarification
i am not able to understand what the challenge is asking me to do... could u please clear what the challenge is??
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;
}
}
1 Answer
Grigorij Schleifer
10,365 PointsHi Sachin,
in this challenge you need to build a method "getTileCount" that accepts a char "tile" as an argument. Inside this method you need to use a for loop to go through every char of the mHand and compare it with your argument "tile", that you has passed inside the getTileCount method.
To analize every char in mHand you will need to make a char array of mHand through toCharArray() method. If char "tile" is == char the count will be increased by one. At the end you return an integer that gives you the number of chars that are equal to "tile".
So the code can look like this:
public int getTileCount(char tile) {
int count = 0;
// initial the count is 0
for(char mHandChar: mHand.toCharArray()) {
//for every char mHandChar" in the array of chars from mHand
if(mHandChar == tile) {
// your condition
count++;
}
}
return count;
}
Please let me know if you need more help
Grigorij
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHi sachin,
do you need more help?
Grigorij