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

Brandon Wash
PLUS
Brandon Wash
Courses Plus Student 1,186 Points

Create a helper method that returns whether or not the GoKart needs to be charged. Make it public and name it isBatteryE

Still have some difficulty writing out this code?

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

  public boolean isBattery Empty () {
  return mBatteryCount == 0;
  }
   public GoKart(String color) {
    mColor = color;
    mBarsCount = 0;
  }


  public String getColor() {
    return mColor;
  }

  public void charge() {
    mBarsCount = MAX_BARS;
  }
}
Kevin Gresmer
Kevin Gresmer
3,020 Points

You have the identifier as "isbattery Empty" in your method but you can't have spaces in the method identifier(or name).

Try;

public boolean isBatteryE() { return mBatteryCount == 0; }

5 Answers

T K
T K
1,875 Points

this is how it goes....

public boolean isBatteryEmpty() { return mBarsCount == 0; }

Yep, that's the right answer!

Kevin Gresmer
Kevin Gresmer
3,020 Points

My bad. We were looking at the wrong variable. mBatteryCount doesnt exist. We need to focus on mBarsCount.

public boolean isBatteryE() { return mBarsCount == 0; }

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 boolean isBatteryEmpty(){ boolean isBatteryEmpty = isFullyCharged(); return isBatteryEmpty; }

public boolean isFullyCharged(){ boolean charged = false; if(mBarsCount == MAX_BARS) { charged = true; } return charged; }

public String getColor() { return mColor; }

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

Brandon Wash
PLUS
Brandon Wash
Courses Plus Student 1,186 Points

Hello Kevin,

Thanks for replying to my question. I have just put in the code public boolean isBatteryEmpty() { return mBatteryCount == 0; } The code is not executing

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

public boolean isBatteryEmpty () { return mBarsCount == 0; }

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

public String getColor() { return mColor; }

public void charge() { mBarsCount = MAX_BARS; }

}