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 Remaining Tries

luis martinez
luis martinez
2,480 Points

why on the class game.java method getRemainingTries() you put mMisses.lenght(); why cant you just put mMisses();

public int getRemainingTries() { return MAX_MISSES - mMisses.length(); }

1 Answer

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

mMisses represents an object of the String class. I don't remember from back then, but I don't believe you create a method mMisses();

You may be thinking why not do:

public int getRemainingTries() { 
    return MAX_MISSES - mMisses;

The thing is, that is essentially saying take MAX_MISSES (which is an integer value) and subtract a string from it, which doesn't make sense.

You want to subtract another integer from MAX_MISSES (in this case the number of times you have already "missed". You can get the number of times you have missed by getting the length of the string mMisses since you increase the size of mMisses by one each time you miss.

The length of a string can be determined with the 'length(); method.... or in this case specifically mMisses.length().

I hope that answers your question.