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 trialFathima Fas-ha
6,847 PointsJava Objects
I tried in many ways but always same Bummer occurs !! please help me to do this challenge task. Although I used an if statement it still says to use the if statement!!! The task is to modify the hasTile method.
public class ScrabblePlayer {
// A String representing all of the tiles that this player has
private String tiles;
public ScrabblePlayer() {
tiles = "";
}
public String getTiles() {
return tiles;
}
public void addTile(char tile) {
tiles+=tile;
// TODO: Add the tile to tiles
}
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
}
}
2 Answers
Yanuar Prakoso
15,196 PointsHi there
The fastest solution you can do is to do this. Please note that the task (as far as I remember) just saying if... then.. but it does not specify you must use if statement:
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
return (tiles.indexOf(tile) != -1);
}
Please note that the method hasTile only expect you to return boolean statement!
If you still want to use if statement and have the long way around you can do this:
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
if(tiles.indexOf(tile) != -1){
return true;
} else{
return false;
}
}
I hope this can help a little.
Fathima Fas-ha
6,847 Pointsit worked !!! thank you !!
Fathima Fas-ha
6,847 PointsFathima Fas-ha
6,847 PointsThanks a lot!! I tried both ways but still it says to "Bummer! While you could definitely solve this using an if statement, try returning the result of the expression." did you do try the challenge ? did this worked well on your workspace? thanks once again!!!