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

Shreekrishna Bellubbi
Shreekrishna Bellubbi
3,121 Points

i did not understood this task?

i am confused about requirement. which String i have to compare and increment count? thank you for help.

ScrabblePlayer.java
public class ScrabblePlayer {
  private String mHand;
  private int count;
  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;
  }
  public int getTileCount(){
  for ( String letter: mHand.toCharAt()){
  if(
  }  
  return count;
  } 
}

2 Answers

Christopher Earle
PLUS
Christopher Earle
Courses Plus Student 22,340 Points

Hi Shreekrishna,

The challenge requirement is to count the number of tiles in the player's hand (mHand) that match a specific tile. The getTileCount method will require an argument similar to the addTile and hasTile methods. For example,

public int getTileCount(char tile) {
  int count = 0;
  for (char letter : mHand.toCharArray()) {
    //Compare if tile equal to letter
      //If true, increment count
  }
  return count;
}
Shreekrishna Bellubbi
Shreekrishna Bellubbi
3,121 Points

thank you christopher really appreciate it.

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

I posted a fairly detailed explanation of the solution to this challenge and what they're actually asking for a while back. Take a look and see if it helps (hope it does)! https://teamtreehouse.com/community/help-to-solve-code-challenge-also-please-explain-the-logic-and-thanks-in-advance