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

Hangman challenge task 2 - compiler returns "Note: JavaTester.java uses unchecked or unsafe operation." - I need a clue!

I'd like to know what the compiler is complaining about, and, if my code is even close (to check to see if a tile drawn is already in the players string, yes=true, else false.

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
    if (tile = answer.indexOf(tiles) != -1) {
      return true;
    } else {
    return false;
   }
  }

}

1 Answer

Hello

if (tile = answer.indexOf(tiles) != -1) { return true;

you probably mean:

if (tiles.indexOf(tile) != -1) { return true; }

ore you could do all in one line:'

return tiles.indexOf(tile) != -1;

If this answers your question please mark the question as answered.

Mark, what an over-achiever (wink)! Both answers resolved the compiler issue (which I'll analyze later) and the second answer, the one-liner, met my instructor's expectations. The first answer was deemed as 'You could use an if statement there...' wasn't what the instructor was looking for, even though it did compile.

Thanks Mark, I've marked this 'Best Answer' Will A