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

Java Objects, Scrabble game. Need Help please

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

Mahalo's

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

    }

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

1 Answer

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hola,

The key here is the word "add" The char represents a single letter. So for example "E" is a char. So I need to add char to mHand. I can do this two ways. I put both examples below, so if you just copy the code, be careful.

public class ScrabblePlayer {
    private String mHand;

    public ScrabblePlayer() {
        mHand = "";
    }

    public String getHand() {
       return mHand;
    }

    public void addTile(char tile) {
//Example 1
        mHand += tile; 
//Example 2
        mHand = mHand + tile;

    }

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

That is how you add a character to the variable mHand of type String. Let me know if this solved your answer, likes are always a bonus lol.

Thanks!