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

hasTile

A little stuck at this point. I feel like I am supposed to pass in a boolean. But I'm not quite sure how to go about it. I was pretty sure with the answer that I had that an if or an else statement wasn't necessary. The hints that it gives are just boggling my mind even farther.

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
    return tiles.indexOf(tile) >= 0;
  }

}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Tim Miller! You're doing fantastic! Actually, you have the second step correct, which is arguably the more difficult of the two. It's the first step that you got a little off. I'm not sure if the checker is a little odd or if you happened to guess what it was adding.

You have this:

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

So let's say I call addTile("z") it's going to take the tiles string and append a 't' to it. Wait. Why a 't'? :smiley: I would like for it to append the tile I sent in!

What you meant to do was append whatever character we happen to send in.

  public void addTile(char tile) {  // tile is our parameter that catches what we send in
    // TODO: Add the tile to tiles
    tiles += tile;  // add what we sent in to the tiles
  }

Hope this helps! :sparkles:

You are simply an inspiration Jen. Thank you again