Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Creating the MVP For Each Loop

Alexandru Constantin Sirbu
Alexandru Constantin Sirbu
3,419 Points

Error says I forgot to add the method getTileCount that accepts chars:

I don't understand what I'm doing wrong. I think I'm missing something. If someone could take a look at my code and give me some tips that would be great

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 String getTileCount()
  {
    String count = "";
    for (char tile: mHand.toCharArray())
    {
      String displayCount = "";
      if (mHand.indexOf(tile) >= 0)
      {
       displayCount += tile;
      }
      count += displayCount;
    }
    return count;
  }  
  public boolean hasTile(char tile) {
   return mHand.indexOf(tile) > -1;
  }
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Here's a couple of hints. The function getTileCount should return an integer and accept a character. Right now yours returns a String and accepts nothing. The declaration of the function should look like this:

public int getTileCount(char tile)

Not long ago I posted a rather detailed explanation and solution to this challenge. If you still need assistance you can find it here: https://teamtreehouse.com/community/help-to-solve-code-challenge-also-please-explain-the-logic-and-thanks-in-advance