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

plz i need help with this java challenge question

the question => "can you also please help me write out the hasTile method? it should return true if the hand has the tile, and false if it dosen't."....plz i need assistance with this question

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) {
      addTile(char tile);
      if (addTile(char tile)) {
        return true;
      }else{
       return false;
    }

    }
}

3 Answers

Geovanie Alvarez
Geovanie Alvarez
21,500 Points

Ok in the hasTile method do this

public boolean hasTile(char tile) {
    return mHand.indexOf(tile) > -1; // this will return true if the tile found in the mHand variable
}

On the addTile line you need to declare a boolean variable. So : boolean addTile(char tile);

thanks everyone! i appriciate!