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 For Each Loop

Kshatriiya .
Kshatriiya .
1,464 Points

Confused at the challenge question

hello,

This may sound strange but i've never played scrabble before in my life and I'm very confused at what the question is asking me to do. I've looked up how to play scrabble but it doesn't really help. Can someone give me a pointer on this please?

Thank you.

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) {
   return mHand.indexOf(tile) > -1;
  }
}

This is my current attempt but its not accepting

   public int getTileCount () {
    int tileCount =0;
    for (char tile: mHand.toCharArray()) {
      if (mHand.indexOf(tile) >= 0) {
      tileCount += 1; }
    }
    return tileCount;
  }

1 Answer

Seth Kroger
Seth Kroger
56,414 Points

Because you are being asked to count the number of tiles that match a particular letter, you'll need to pass that letter to the method as a char argument. Then in the for loop as it goes through each tile of the hand, you'll need to compare that letter to the current tile