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 trialtrell story
1,520 PointsStill not working out... going to take a break and come back later
The error wants the call to come from the "while" ... but it's not working out...still. I am taking break and coming back later....
public class GoKart {
public static final int MAX_ENERGY_BARS = 8;
private String mColor;
private int mBarsCount;
public GoKart(String color) {
mColor = color;
mBarsCount = 0;
}
public String getColor() {
return mColor;
}
public void charge() {
mBarsCount = MAX_ENERGY_BARS;
}
public boolean isBatteryEmpty() {
return mBarsCount == 0;
}
public boolean isFullyCharged() {
boolean isCharging = false;
while(isBatteryEmpty()){
mBarsCount++;
isCharging = true;
}
while (!isCharging) {
mBarsCount++;
} return isCharging;
}
}
2 Answers
Geovanie Alvarez
21,500 PointsYou need to do the while loop inside of the charge method not in the isFullyCharged
public void charge() {
while(!isFullyCharged()){
mBarsCount++;
}
}
and leave the isFullyCharged
public boolean isFullyCharged() {
return mBarsCount == MAX_ENERGY_BARS;
}
trell story
1,520 PointsThanks, man but that was handled yesterday morning...... Peace...
Peng Liu
Courses Plus Student 14,273 PointsPeng Liu
Courses Plus Student 14,273 PointsAlvarez is right, before put these codes in, you need to reset the code to default(it gives you this option alongside check work on the challenge page).
Peng