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

Schwartz Prince
PLUS
Schwartz Prince
Courses Plus Student 2,132 Points

Couldn't get the answer for this code.

This code shows me bummer. I couldn't spot out the error in the program. It would be great if someone can please help me in this.

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) {
    // TODO: Add the tile to tiles
    tiles += tile;

  }

  public boolean hasTile(char tile) {
    // TODO: Determine if user has the tile passed in
    boolean tls = tiles.indexOf(tile) != -1;

    if (tls >= 0){
      return true;
    } else{
    return false;
  }}

}
Miguel Rivas
Miguel Rivas
4,902 Points

Hello Schwartz, if I'm right that challenge doesn't want you to solve the 2nd part with an 'if' statement, but since I don't know which kind of 'bummer error' is showing you, you could try this:

  public boolean hasTile(char tile) {
    // TODO: Determine if user has the tile passed in
    return tiles.indexOf(tile) >= 0; 
  }

Hope this works for you.

Regards;

M.

Schwartz Prince
Schwartz Prince
Courses Plus Student 2,132 Points

Hi Miguel, Thank you for your response. But still the program shows me an error. Please help me in sorting it out.

1 Answer

Miguel Rivas
Miguel Rivas
4,902 Points

Schwartz, I see 2 } in the final method 'hasTile'.

I'm pretty sure you have a problem with those, don't be afraid to restart the challenge and write the code again.

If you understand the tasks then the only lines of code you need are these two:

// TODO: Add the tile to tiles
    tiles += tile;

// TODO: Determine if user has the tile passed in
    return tiles.indexOf(tile) >= 0;

Let me know if that works for you.

M.