Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Creating the MVP Scrabble Tiles

Lyndsi Barfield
Lyndsi Barfield
633 Points

I can not figure out what to do for this question. I'm honestly lost and don't where to start.

I attempted the code but I'm clearly not getting it right.

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 += tile;


  public boolean hasTile(char tile) {
    // TODO: Determine if user has the tile passed in
    if (isTile) {
     tiles +- tile; 
    } else {
      != tiles +- tile;
    return false;


1 Answer

Michael Poley
Michael Poley
8,769 Points

This is a tough challenge. I had trouble with this one too because I was also trying to use an if/else statement. But the code challenge has an easier solution in mind.

In the video before the challenge Craig talks about using the indexOf method in order to return the index of a letter in the hangman answer.

indexOf('e') != -1;

In this case, the indexOf method is going to check the letter 'e' against the answer. If the letter 'e' is present then the index will be greater than -1.

For the hasTile method in the code challenge, you want to check against the tiles to see if the tile is present. If the tile's index is greater than -1, then the tile is present – and returns true.

public boolean hasTile (char tile) {
return tiles.indexOf(tile) != -1;