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) Harnessing the Power of Objects Helper Methods and Conditionals

Eleni Minadaki
Eleni Minadaki
3,687 Points

Create 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
PLUS
William Li
Courses Plus Student 26,868 Points

If 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.

Hi 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?:

  public boolean isFullyCharged () {
    return MAX_BARS == 8;
  }
William Li
William Li
Courses Plus Student 26,868 Points

hi, 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 the isFullyCharged(), as the purpose of this method is supposed to return false when mBarsCount is NOT equals to the MAX_BARS, and true otherwise.

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

May I see your code? You didn't provide your implementation of isFullyCharged here

Eleni Minadaki
Eleni Minadaki
3,687 Points

Thanks William for your answer!

Eleni Minadaki
Eleni Minadaki
3,687 Points

not yet,iam confused.here is my code { mBatCount = Full_BatCount; }

Hi 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.