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

Ray Cabatingan
Ray Cabatingan
3,549 Points

Confused.... :( please help

don't get why there is a return false;

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) {
       boolean Hand = mHand.indexOf('tile');
       return false;
    }
}

2 Answers

ALBERT QERIMI
ALBERT QERIMI
49,872 Points

hmm you need to read questions more carfylly is asking - It should return true if the hand has the tile, and false if it doesn't. you can solve it in many diffirent ways

1)  if ( indexOf(tile) >= 0) {
        return true;
      } else {
        return false;  
      }
    }
}
2) public boolean hasTile(char tile) {
      boolean currentHand = mHand.indexOf(tile) >= 0;
      if(currentHand){
        return true;
      } else {
        return false;
      }
    }

or the easyiest way craig also did it in video is just

return mHand.indexOf(tile) >= 0;

it will returun true if indexOf tile is > than 0 or false in other case

Thanks