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

stuck on code challenge Helper Methods

im stuck on this quiz please help. here is my code,

public class GoKart {
  public static final int MAX_BARS = 8;
  private String mColor;
  private int mBarsCount;

  public GoKart(String color) {
    mColor = color;
    mBarsCount = 0;
  }

  public String getColor() {
    return mColor;
  }
  public boolean isBatteryEmpty () {
       return  mBarsCount == 0;
  }
  public boolean isFullyCharged () {
    if (Kart == isBatteryEmpty()) {
     return true;
  }

  }

  public void charge() {
    mBarsCount = MAX_BARS;
  }
}

4 Answers

Hi. It is possible to write the isFullyCharged() helper method as a single return statement, exactly as you did with isBatteryEmpty(). Instead of checking to see if mBarsCount is equal to zero, you'll want to check to see if mBarsCount is equal to the maximum possible number of bars.

It's not necessary to use the if() statement at all, but if you wanted to go that route for some reason, you would also want the parenthetical statement to evaluate whether mBarsCount was equal to the maximum number of bars. The statement you are currently evaluating is confusing, because Kart is not a previously declared variable and isBatteryEmpty(), if false, would only indicate that the battery had more than zero bars and not necessarily the maximum number of bars.

Let me know if you have any additional questions or if there is something I can explain better. Good luck!

Hi Diana could you put an example?

missgeekbunny
missgeekbunny
37,033 Points

Can't remember off hand what you are supposed to accomplish in that challenge. Can you include it so we can help you better?

missgeekbunny
missgeekbunny
37,033 Points

For the challenge you want to put if it is fully charged which you would check against MAX_BARS not isBatteryEmpty

Thank you to both of you!