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 trialTim Miller
781 PointshasTile
A little stuck at this point. I feel like I am supposed to pass in a boolean. But I'm not quite sure how to go about it. I was pretty sure with the answer that I had that an if or an else statement wasn't necessary. The hints that it gives are just boggling my mind even farther.
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) {
// TODO: Add the tile to tiles
tiles += 't';
}
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
return tiles.indexOf(tile) >= 0;
}
}
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Tim Miller! You're doing fantastic! Actually, you have the second step correct, which is arguably the more difficult of the two. It's the first step that you got a little off. I'm not sure if the checker is a little odd or if you happened to guess what it was adding.
You have this:
public void addTile(char tile) {
// TODO: Add the tile to tiles
tiles += 't';
}
So let's say I call addTile("z")
it's going to take the tiles
string and append a 't' to it. Wait. Why a 't'? I would like for it to append the tile I sent in!
What you meant to do was append whatever character we happen to send in.
public void addTile(char tile) { // tile is our parameter that catches what we send in
// TODO: Add the tile to tiles
tiles += tile; // add what we sent in to the tiles
}
Hope this helps!
Tim Miller
781 PointsYou are simply an inspiration Jen. Thank you again