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

Stuck on Scrabble challenge task 2

Hi,

I am working on a java methods challenge for creating a Scrabble game. I am on task 1 of 2. It says I have to fill out the hasTile method to pass a true char if a hand has a tile, and false if it doesn't. The code you see here is what they gave me, and what I completed in the first task of this challenge. Could you please include some code on what I need to do to fix this? Thank you!

ScrabblePlayer.java
public class ScrabblePlayer {
    private String mHand;

    public ScrabblePlayer() {
        mHand = "";
    }

    public String getHand() {
       return mHand;
    }

    public void addTile(char tile) {
     boolean hasTile = mHand.indexOf(tile) >= 0;
      mHand += tile;
        // Adds the tile to the hand of the player

    }

    public boolean hasTile(char tile) {


       return false;
    }
}

1 Answer

The only line you need in the addTile method is this:

mHand += tile;

Remove the other one. Now for task 2, you are required to implement the hasTile method. So you need to do a check with the redundant line from task one:

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