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

Don't know the next step - Slightly confused on what method I call and why

Explanation please.

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

    public boolean hasTile(char tile) {
       return false;
    }
}
Joakim Mattsson
Joakim Mattsson
3,074 Points

He wants you to change the hasTile method.

You should check if the mHand string contains the char tile. A nice way to do this is by using the string method indexOf()

for example

mHand.indexOf(tile)

Remember that this method returns an int. If it contains it will return 0 or bigger. If it does not contain the letter it will return -1.

Hope this helps.

1 Answer

Here is what I did:

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

    }

    public boolean hasTile(char tile) {

      for(char letter : mHand.toCharArray()){

        if(letter == tile)
          return true;
      }
      return false;
    }