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 trialBrandon Wash
Courses Plus Student 1,186 PointsCreate 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?
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;
}
}
5 Answers
T K
1,875 Pointsthis is how it goes....
public boolean isBatteryEmpty() { return mBarsCount == 0; }
Augusto Hernandes
1,818 PointsYep, that's the right answer!
Kevin Gresmer
3,020 PointsMy bad. We were looking at the wrong variable. mBatteryCount doesnt exist. We need to focus on mBarsCount.
public boolean isBatteryE() { return mBarsCount == 0; }
Alain Breton
2,656 Pointspublic 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
Courses Plus Student 1,186 PointsHello 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
Nitin bahri
7,063 Pointspublic 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; }
}
Kevin Gresmer
3,020 PointsKevin Gresmer
3,020 PointsYou 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; }