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

Terrence Adderley
PLUS
Terrence Adderley
Courses Plus Student 775 Points

Can someone please look at my code !

I am stuck, I believe that my error lies in my if else statement but my Boolean might be falsely set up as well. Please help !

ScrabblePlayer.java
public class ScrabblePlayer {
    private String mHand;

    public ScrabblePlayer() {
        mHand = "";
    }

    public String getHand() {
       return mHand;
    }

    public void addTile(char tile) {
       mHand += tile;  // Adds the tile to the hand of the player

    }

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

      } else {
      hasTile < 0;
      }

      return false;
    }
}

2 Answers

Nicholas Olsen
seal-mask
.a{fill-rule:evenodd;}techdegree
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Points

Well, it is not clear what the problem is. Are you getting an error? Just looking at your code I can tell you that your hasTile method doesn't do anything but return false. Is that the problem?

boolean hasTile = mHand.indexOf(tile) >= 0;

The above statement returns true if tile is found and returns false if tile is not found. and then just

return hasTile; 

hasTile is a boolean and cannot be used to compare with >0 and <0,

Also it's same as you method name hasTile, I think they should be different.

One possible way for the your final code is below.

boolean gotTile = mHand.indexOf(tile) >= 0;
return gotTile; 

Others can correct or confirm.