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 Creating the MVP Counting Scrabble Tiles

need help w/ this code

i dont get what am i soppose to compare the char "letter" to, i know its the chars from the String "tiles" but how am i soppose to get them?

ScrabblePlayer.java
public class ScrabblePlayer {
  // A String representing all of the tiles that this player has
  private String tiles;

  public ScrabblePlayer() {
    tiles = "";
  }

  public String getTiles() {
    return tiles;
  }

  public int getCountOfLetter(char letter) {
    int count = 0;
    for (char letters : tiles.toCharArray()){
      if(letter == )
    }
    return count;
  }

  public void addTile(char tile) {
    tiles += tile;
  }

  public boolean hasTile(char tile) {
    return tiles.indexOf(tile) != -1;
  }
}

1 Answer

Hi there,

You've got this!

You have correctly converted the tiles to a char array. Try calling the loop variable something different to the value passed into the method - try tile. Then, at each loop, compare, using ==, whether tile is equal to letter, the char passed into the method. If they are equal, increment count.

Make sense?

Steve.

got it, thank you so much!

No problem! :+1: :+1: