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 trialsolange tuyisenge
3,081 PointsI need help on task challenge"https://teamtreehouse.com/library/java-objects/creating-the-mvp/for-each-loop"
I am getting a can not find symbol error and it says variable mHand of type string. i can not figure out where I went wrong.
Thank you for assisting
Solange
solange tuyisenge
3,081 Pointspublic 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(){ int tileCount=0; for (char tile: mHand.hasTile()){ if(mHand.indexOf(tile) > -1){ tileCount++; } } return tileCount; } }
2 Answers
Grigorij Schleifer
10,365 PointsHi Solange,
here a code proposal:
public int getTileCount(char tile){
// to proof a specific char inside mHand you need to give that chat as parameter
int tileCount=0;
for (char tileToProof: mHand.toCharArray()){
// you cant use hasTile() method on mHand because mHand is a String
// 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(tileToProof == tile){
// condition to increment tileCount
// if a char from mHandArray equals to the argument char
// increment the count
tileCount++;
}
}
return tileCount;
}
Let me know if this was helpful or not ...
Grigorij
solange tuyisenge
3,081 PointsMany thanks Grigorij,
It was so helpful.
Regards,
Solange
Grigorij Schleifer
10,365 PointsNice !!!!
Shout out here in the forum if you need more help
Grigorij
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHi Solange,
can you post your code?
Grigorij