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

Mateusz Kruk
Mateusz Kruk
550 Points

Help with Challenge 1 of 2

I'm trying my best to use the Game.java code as an example of what we want to enter into this challenge, but I'm having trouble understanding it. What does it mean by append the tile that was passed in? What make this challenge different from the video hangman code? Thank you for the help!

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

1 Answer

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

Hi there, Mateusz Kruk! You're doing great! And yes, it does add the tile to tiles but then nothing further happens. It goes up for garbage collection. What you're meaning to do is add the tile to tiles and then assign it back into tiles so that the result is saved.

You could do this a couple of ways:

tiles = tiles + tile;

Or you could do:

tiles += tile;

Either one of those takes tiles, appends/concatenates the tile onto the end and then sets the value of tiles to the result. This means that each additional tile you add will go on the end.

So if I did:

addTile("m");
addTile("a");
addTile("t");

The value of tiles would be "mat" :smiley:

Hope this helps! :sparkles:

P.S. This doesn't differ from the hangman game shown. Check out the code around 8:14 of the previous video. Particularly, the variables hits and misses.