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 (Retired) Creating the MVP Strings and Chars

Below is an object that I am using to represent a player in a Scrabble-like game I'm building. The mHand field is used t

What should I do ?!!! Below is an object that I am using to represent a player in a Scrabble-like game I'm building. The mHand field is used to represent all the tiles the user currently has in their hand.

Can you please fill out the addTile method so that it takes the char that is passed and adds it to the mHand member field? Thanks!

ScrabblePlayer.java
public class ScrabblePlayer {
    private String mHand;

    public ScrabblePlayer() {
        mHand = "";
    }

    public String getHand() {
       return mHand;
    }

    public void addTile(char tile) {
        // Adds the tile to the hand of the player
      boolean mHand = getHand;

    }

    public boolean hasTile(char tile) {
       return false;
    }
}

4 Answers

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,723 Points

Hi ahmed

You need to add the tile to your mHand variable:

mHand += tile;

It looks like you're storing the tiles as a string. You can just use += to add the new charachter.

public void addTile(char tile) {
        // Adds the tile to the hand of the player
      mHand += tile;

    }

thanks it helped

Oh thanks a lot