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 trialDarin Thompson
5,305 Pointscreating an eatPez(); method
I am trying to create a method that "eats" a PEZ candy and then reduces the mPezCount by one and then returns a silly string about eating the candy and the current count. I get keep getting an error about not being able to convert int to string, but I don't see how that's happening or why. Any Advice?
Darin Thompson
5,305 PointsHey guys, thanks for the responses. I figured it out. It was the fact that I had it as a String instead of an int. And I believe that I had the method doing too many things. Once I slowed down and separated things out it figured it out.
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsNot a problem. Glad to help!
1 Answer
markmneimneh
14,132 PointsHello
I suspect you are returning mPezCount by mistake
Let me explain:
if you have a method like this
public String eatPez(){ if(mPezCount > 0) { mPezCount =- 1; return mPezCount ; //this is wrong }else { return "No Pez to eat. Please add Pez"; } }
what you may be looking for is
public String eatPez(){ if(mPezCount > 0) { mPezCount =- 1; return "YUM! YUM!" }else { return "No Pez to eat. Please add Pez"; } }
Hope this helps
If this answers your question, please mark as answered.
Thanks
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsChris Jones
Java Web Development Techdegree Graduate 23,933 PointsIs the mPezCount variable declared as a String or int? It will be easier to help if you can post your method's code.