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 trialNeil Gordon
8,823 Pointspassing objects in methods
i'm not sure if i am thinking through this correctly. I would appreciate a bit of methodology here.
public class ScrabblePlayer {
private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
// Adds the tile to the hand of the player
String new tile = mHand + tile;
}
public boolean hasTile(char tile) {
return false;
}
}
4 Answers
Grigorij Schleifer
10,365 PointsHi Neil,
First task wants you to pass a tile to mHand
public void addTile(char tile) {
mHand += tile;
}
Second task wants you to proof whether the tile is in the mHand or not and return true if tile is in mHand or false if not
public boolean hasTile(char tile) {
if (mHand.indexOf(tile) < 0) {
return false;
// indexOf() method returns -1 if the char is missing
}
// if indexOf returns 1, the tile is inside mHand
return true;
}
Grigorij
Neil Gordon
8,823 Pointsawesome.
Neil Gordon
8,823 Pointspublic void addTile(char tile) { // Adds the tile to the hand of the player String new tile = mHand + tile;
}
Neil Gordon
8,823 PointsThank you, i didn't understand that one at all , will have to review the video on passing
Grigorij Schleifer
10,365 PointsYou are very welcome. I review the complete java course again. It is a lot of work, but I understand so much more now. And the challenges are very complex in the beginning and now they start to make much more sence ...