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 trialEleni Minadaki
3,687 PointsCreate a helper method named isFullyCharged. It should return true if the GoKart is at max capacity.
Hi!I Try to find what's i have do wrong in my code but i can't. Here is the code: public void Charge() { mBatCount = Full_BatCount; } Thanks for any help!
4 Answers
William Li
Courses Plus Student 26,868 PointsIf you are still confused.
public boolean isFullyCharged() {
return mBarsCount == MAX_BARS;
}
pretty straightforward here, you test whether mBarsCount is equal to MAX_BARS, that's how you know if it's fully charged.
William Li
Courses Plus Student 26,868 PointsMay I see your code? You didn't provide your implementation of isFullyCharged here
Eleni Minadaki
3,687 PointsThanks William for your answer!
William Li
Courses Plus Student 26,868 Pointsso you figured it out yet?
Eleni Minadaki
3,687 Pointsnot yet,iam confused.here is my code { mBatCount = Full_BatCount; }
A X
12,842 PointsHi Eleni, I know you responded a year ago to this, but in case you're still out there you haven't told the program what Full_BatCount is. So more simply, it's like me coming up to you and asking for a shoofly pie (I'm assuming that you don't already know what one is...as a shoofly pie is a real type of pie). If you don't know what that is, then you'd be confused and unable to come up with an image of one inside your brain. That's exactly the same case here. The program has no idea what you're talking about until you tell it what Full_BatCount is somewhere else first.
A X
12,842 PointsA X
12,842 PointsHi William, I'm going through this code challenge, and I'm curious why this version is incorrect because isn't the condition for returning exactly the same as mBarsCount == MAX_BARS since the MAX_BARS is 8?:
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 Pointshi, abbymann because line 2 in the code
public static final int MAX_BARS = 8;
MAX_BARS has already been initialized as integer 8, comparing
MAX_BARS == 8
therefore always yields true, which is a semantic fault for theisFullyCharged()
, as the purpose of this method is supposed to return false when mBarsCount is NOT equals to the MAX_BARS, and true otherwise.