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

Lost trying to complete addTile() method. I can't wrap my head around the solution. Please help?

This is what I did so far: //Set the argument to be passed. char aTile = tile;

// Add tile to mhand member field. aTile += mhand;

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
      char aTile = tile; 
      aTile += mHand;

    }

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

1 Answer

 char aTile = tile; 
      aTile += mHand;

this is wrong. aTile += mHand means aTile + mHand = aTile yet we want to increament mHand not a Tile.

instead of the above code just do the following. Please notify me if it works.

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

    }

Thank you Blessing Kabasa, yes this works. Currently trying to get into the mind set of talking myself through solutions as you did with this but its not working out so well right now. Thanks for responding to my problem!