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 trialPetter Jonasson
808 PointsHi, I am super greatful for every response i get, and my sorry ass needs some more help.
Okay, so I need to count how many occurrences of a a specific letter is in the player's tiles. Let's build that over a couple of steps. I've added some example use cases in Example.java
Create a new method named getCountOfLetter that returns an int, and requires a parameter of type char named letter. For this task, just make it return 0.
I am super bad at coding but i think it is fun so i would love some help.
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() {
int letter = 0;
for (char letter : letter.toCharArray()) {
System.out.println("0");
}
}
}
1 Answer
Steve Hunter
57,712 PointsHi there,
The first task says: Create a new method named getCountOfLetter that returns an int
, and requires a parameter of type char
named letter
. For this task, just make it return 0.
So, your code needs a little adjustment. First, you want the method to receive a parameter of type char
which is called letter
. Inside the method, you just want to return a zero at this stage:
public int getCountOfLetter(char letter){
return 0;
}
The next task uses the toCharArray
with a for
loop to see if letter
is contained in tiles
and to count how many times it occurs.
Let me know how you get on.
Steve.