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

Nicole Favela
Nicole Favela
1,342 Points

I can't figure out this hasTile boolean. I keep getting a compiler error. What am I missing?

Is the currentHand boolean necessary , or is it enough to check if mHand>=0??

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 currentHand = mHand.indexOf(tile) >= 0;

      if(currenthand){
        return true;
      } else {
        return false;
      }

    }
}

2 Answers

Allan Clark
Allan Clark
10,810 Points

You can directly return the conditional statement like this:

return mHand.indexOf(tile) >= 0;
Nicole Favela
Nicole Favela
1,342 Points

Thanks!! that worked. I thought I needed an if else statement.

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Nicole be sure you select Allan Clark's response as the correct answer if this solved your issue. I was looking in the "Unanswered questions" with 5 months without an answer. Even though there is an answer, if you select - I believe its the "Best Answer" button - it will take you out of the unanswered category.

It will also highlight the right answer in green so other users with the same issue will see the proper answer that worked for you. :)