0

I need to use a enhanced for each loop, I need to return a number representing the count of tiles that match the letter that was passed into the method. I don't know what to use for that. IndexOf? charAt? Equals? Ignore the comments, I wasn't sure what needed to go there or if I needed something there.

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 void addTile(char tile) {
        tiles += tile;
    }

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

    public int getCountOfLetter(char letter){
        int countOfTiles = 0;
        //ScrabblePlayer player1 = new ScrabblePlayer();

        for (char letters : tiles.toCharArray()) {
            //int display = 0;
            if (tiles.equals(letters)) {
                //display =
                countOfTiles++;
            }
        }
        return countOfTiles;
    } 
}
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Joshua Thao
  • 63
  • 1
  • 9

0 Answers0