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

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;
}