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

srabble task 2

i can not get answer right? i want to know where did i get wrong

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 += "t";
  }

  public boolean hasTile(char tile) {
    // TODO: Determine if user has the tile passed in
  boolean hasTile = tiles.indexOf(tile)
      if (hasTile = -1) {
        return false;
    } else {
        return true;
      }

}

2 Answers

That line also give me a error message but i was able to find my error. Thank you Richard Lambert

Richard Lambert
PLUS
Richard Lambert
Courses Plus Student 7,180 Points

Hello mate,

I like your thinking and can see what logic you're trying to implement within the .hasTile(char tile) method. With just a few alterations you would have a correct implementation:

public boolean hasTile(char tile) {
    int hasTile = tiles.indexOf(tile);    // .indexOf(char c) returns a value of type int not boolean
    if (hasTile == -1) {    // == for test of equality not = for assignment
      return false;
    } else {
      return true;
    }
}

BUT, this is not the implementation the Treehouse Java test engine is expecting to see.

Hope this helps

i still can not get the answer

Richard Lambert
Richard Lambert
Courses Plus Student 7,180 Points

Try this Sachini Hansini Nawalaella:

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