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 trial

Java Java Objects Creating the MVP Scrabble Tiles

How do I complete the Scrabble challenge?

Hello, I can't seem to get past this part of the challenge in the Java Objects lesson. I originally glossed over the detail of returning the value of the expression in the instructions (I used an if statement) and got an error. I fixed the issue, no biggie, but I came to the realization that by using return and then seeing if the tile was in the tiles field, I could not also return it true, as the compiler cannot get passed the first return statement to the next. I have tried looking at other people's questions, but I can't figure it out. I don't know what to do. (Hopefully I'm not overlooking a small detail that could help me) I would really appreciate some guidance. I'm really sorry if I'm being kind of obtuse! Thanks!

ScrabblePlayer.java
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 += 't';
    // TODO: Add the tile to tiles

  }

  public boolean hasTile(char tile) {
    return (tiles.indexOf(tile) != -1);
    //Compiler says that this below is unreachable
      return true;
  }

}

1 Answer

Emmanuel C
Emmanuel C
10,636 Points

You can just delete the second return as the logic in the first return works fine.

Theres a problem in the addTiles method though, It's suppose to add the parameter tile instead of just the char 't'. The quiz is going to use that method to test your whole quiz and will fail because of that.

Thank you so much! I feel kind of like an idiot because that seemed so simple. Thanks for the help!