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

Enyang Mercy
PLUS
Enyang Mercy
Courses Plus Student 2,339 Points

Help!!! add new method type char letter return zero

Please help correct my code.

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

  public void getCountOfLetter(char letter) {
    return 0;
  }

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

2 Answers

Hi there,

For this first task you want to create the method called getCountOfLetter. Let's make it public and build it up from there. We start with:

public getCountOfLetter(){

}

This is incomplete. We know that the method should return an int. The return type goes in front of the method name, after public:

public int getCountOfLetter(){

}

The task says that the method should receive a char called letter as a parameter. Parameters go inside the parentheses after the method name. That looks like:

  public int getCountOfLetter(char letter){

  }

As the method returns an int for this first task, we just want to return zero inside the method; i.e. within the curly braces:

  public int getCountOfLetter(char letter){
    return 0;
  }

That's the first task explained for you - let me know how you get on and that this makes sense.

Steve.

Enyang Mercy
PLUS
Enyang Mercy
Courses Plus Student 2,339 Points

Steve you are a pro! well explained. i mean i just learned something different and new within your lines. thank you very much

Happy to help! :+1: