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

Jacob Luallen
Jacob Luallen
1,947 Points

Trouble with hangman and simple boolean statement.

I need to set up the hasTile method so it will return true if the hand(mHand?) contains the tile and false if otherwise. I should only need a simple boolean statement right? I don't know what I am doing wrong.

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 hasTile = mHand.indexof(tile) >= 0;
      return false;
    }
}

1 Answer

Cristian Altin
Cristian Altin
12,165 Points

In the hasTile function you are always returning false if you write return false;

You should return the boolean variable so that it will return the wanted outcome.

p.s. also be aware of indexOf case sensitivity

Cristian Altin
Cristian Altin
12,165 Points

It's been a pleasure! If my answer brought you to the solution please remember to mark it.