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

Patrick Hanson
Patrick Hanson
7,013 Points

Scrabble Tiles

https://teamtreehouse.com/library/java-objects-2/creating-the-mvp/scrabble-tiles there is a link to the current challenge, task 2. I feel like I'm missing something basic but for the life of me I cant figure it out.

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 isTiles += "tile" ;
    if ( isTiles) {
    tiles += "tile";
    }
    return isTiles;
  }

}

You need to check if the Char tile is in the String tiles. Using the indexOf method will return the index of the char passed in the string, or -1 if it is not found. So, the indexOf method will return zero or a positive number if your char tile is in the string tiles, or it will return -1 if it is not. Hope this helps.

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

2 Answers

Luis Mansilla
Luis Mansilla
4,539 Points

Seems that you should use the indexof in the hastile method.

Neil Kamath
Neil Kamath
2,078 Points

This showed up in my home page as a recommendation after finishing Java Object. But i get redirected to \Library and get the following error message "Bummer! You have been redirected as the page you requested could not be found.". Has this content been relocated or Removed?