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 trialfernandocompres
Courses Plus Student 836 Points./ScrabblePlayer.java:29: error: incompatible types: int cannot be converted to String return count;
hello guys..!! public String getTileCount(char tile){ int count = 0; for(int i =0;i<mHand,length(); i++){ if(mHand.charAt(i) == tile){ count++; } //I placed here too and give me same error. } return count; }
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(char tile) {
int count = 0;
for(int i = 0; i < mHand.length(); i++){
if(mHand.charAt(i) == tile){
count ++;
}
}
return count;
}
}
4 Answers
Kourosh Raeen
23,733 PointsYou've set the return type of the getTileCount() method to String, but it should be int.
fernandocompres
Courses Plus Student 836 Pointsthx Kourosh Raeen and Grigorij. have a question ? why did you place "return count " out of the loop instead of put it inside of the loop?
Grigorij Schleifer
10,365 PointsHey Fernando, sorry for confusion. The placement of the return statement of your code was 100% correct.
Grigorij Schleifer
10,365 PointsHI Fernando,
i have changed your method a little bit:
public int getTileCount(char tile){ // return type is int not String
int count = 0;
for(int i = 0; i < mHand.length() ;i++){
if(mHand.charAt(i) == tile)
count++;
}
}
return count;
}
Makes sense?
Grigorij
Kourosh Raeen
23,733 PointsHi Grigorij - Sorry to be picky but I need to make a correction. Fernando's return statement was already inside getTileCount. The two closing braces above his return statement are for the if and for statements.
Grigorij Schleifer
10,365 PointsHi Kouroush,
you are not picky at all!!! Thank you for the correction. I changed it after I saw my mestake :)
You are great
Grigorij
fernandocompres
Courses Plus Student 836 Pointsthx dude..!!
Grigorij Schleifer
10,365 PointsYou are welcome !!!
And thx to Kourosh for the correction :)
Kourosh Raeen
23,733 PointsHappy coding guys! :)