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 (Retired) Creating the MVP Strings and Chars

Carlos Quevedo
Carlos Quevedo
5,911 Points

Keep getting an error. Do "addTile" or "mHand" belong in the "hasTile" if/else statement?

So I keep writing the following and getting the "cannot find symbol" error, am I writing this if/else statement correctly? Does this even require one? Code below. Am I missing something?

public boolean hasTile(char tile) { if(addTile) { return true; } else { return false; }

2 Answers

Brendon Butler
Brendon Butler
4,254 Points

I'm not sure if you have added any other code other than what you have provided. But there is no "addTile" variable. There is an "addTile()" method that takes a char variable as an input.

This could be used, but the "addTile()" method has a void return type. Which means it doesn't return anything. in order to use "if (addTile(char))" the "addTile()" method would have to have a boolean return type. There's more to it, but that's how it would work.

Answer: The challenge is asking you to do a check to see if the "mHand" variable contains the tile that was passed into the method. There are two ways to do this. You could either check to see if the string ".contains()" the tile (more difficult, more steps needed) or simply to check to see the ".indexOf(char)".

NOTE: .indexOf(char) returns a value of 0 or greater if the string has that char in it. If not, it would return -1. Knowing this, a simple comparator will do the trick.

If this isn't clear enough or maybe you have a question, please, I encourage you to respond. :)

Carlos Quevedo
Carlos Quevedo
5,911 Points

Ah! I get it know. I guess I was confused by the fact that ".indexOf(char)" returns a number and thought it required an "int" or something similar. All a part of the process.

Thanks for all your help, man!