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

Shashank Shekhar
PLUS
Shashank Shekhar
Courses Plus Student 2,437 Points

How to write getTileCount() function ?

My function goes like this :

public int getTileCount(char tile){ int count=0

   for (char letter : mHand.toCharArray()){

        if ( hasTile(letter)){

     count+=1;

    mHand+=letter;

}

else count=0; }

 return count;

}

Can Someone tell me how to figure out this, if this is not going to be the method then what has to be?

1 Answer

Matthew Alexander
Matthew Alexander
14,000 Points
public int getTileCount(char specialTile) {
   int count = 0;
    for (char tile: mHand.toCharArray()) {
      if (tile == specialTile) {
        count++;
      }
    }
    return count;
  }

The hasTile method will return whether there is letter inside mHand. However we are trying to count the number of matching tiles. A great explanation is provided here Lucas Santos's explanation