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

michael lee
michael lee
5,179 Points

what am i doing wrong

can someone tell me what am i doing wrong

ScrabblePlayer.java
public class ScrabblePlayer {
  // A String representing all of the tiles that this player has
  private String tiles;
  private String hits;
  private String misses;

  public ScrabblePlayer() {
    tiles = "";
    hits = "";
    misses = "";
  }

  public String getTiles() {
    return tiles;
  }

  public void addTile(char tile) {
    tiles += tile ;
    // TODO: Add the tile to tiles

  }

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

}

1 Answer

Ruben Ponce
seal-mask
.a{fill-rule:evenodd;}techdegree
Ruben Ponce
Full Stack JavaScript Techdegree Student 12,035 Points

You're almost there. All you need to do is return whether or not the tiles array contains any tile. We can do this with the indexOf method.

public boolean hasTile(char tile) { return tiles.indexOf(tile) >= 0; }

So this will return true if there's a tile, and false if there isn't.