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 trialPatrick Hanson
7,013 PointsScrabble Tiles
https://teamtreehouse.com/library/java-objects-2/creating-the-mvp/scrabble-tiles there is a link to the current challenge, task 2. I feel like I'm missing something basic but for the life of me I cant figure it out.
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) {
// TODO: Add the tile to tiles
tiles += "tile";
}
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
boolean isTiles += "tile" ;
if ( isTiles) {
tiles += "tile";
}
return isTiles;
}
}
2 Answers
Luis Mansilla
4,539 PointsSeems that you should use the indexof in the hastile method.
Neil Kamath
2,078 PointsThis showed up in my home page as a recommendation after finishing Java Object. But i get redirected to \Library and get the following error message "Bummer! You have been redirected as the page you requested could not be found.". Has this content been relocated or Removed?
Hunter Newton
10,065 PointsHunter Newton
10,065 PointsYou need to check if the Char tile is in the String tiles. Using the indexOf method will return the index of the char passed in the string, or -1 if it is not found. So, the indexOf method will return zero or a positive number if your char tile is in the string tiles, or it will return -1 if it is not. Hope this helps.
public boolean hasTile(char tile) { if (tiles.indexOf(tile) >= 0) { return true; } else { return false; }