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

creating an mvp

am running this code and its giving me a bummer may somebody help me where iam wrong.

ScrabblePlayer.java
public class ScrabblePlayer {
    private String mHand;

    public ScrabblePlayer() {
        mHand = "";
    }

    public String getHand() {
       return mHand;
    }

    public void addTile(char tile) {
      mHand += tile;

    }

     public boolean hasTile(char tile) {
      if(mHand.indexOf(tile)){
        return true;
      }else{
       return false;
    }
 }  

2 Answers

Chase Marchione
Chase Marchione
155,055 Points

You're close!

  • Counting your opening and ending curly braces: you need one more at the end of the class, to match the opening brace from your class header.
  • Your if statement is where things get tricky. You want to check if the indexOf the tile is greater than or equal to 0 (or, greater than -1.) This is a boolean (true or false logic) way of testing whether the value is in the mHand String or not, and if an index for that value is indeed in that String (certainly, if there is an index for that value in our String, it is 0 or greater!).
if(mHand.indexOf(tile) >= 0)

Hope this helps!

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Also remember you can return the expression and avoid the if block all together!