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 trialNiyamat Almass
8,176 PointsI have a problem
I done the challenge.But a error.The error code is below
./GoKart.java:29: error: cannot find symbol while (!isEmpty()) { ^ symbol: method isEmpty() location: class GoKart 1 error
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() {
return mBarsCount == MAX_ENERGY_BARS;
}
public boolean isCharged() {
boolean isCharged = false;
while (!isEmpty()) {
mBarsCount--;
isCharged = true;
}
return isCharged;
}
}
Niyamat Almass
8,176 Pointsthank you Jose Cortedano
1 Answer
Rebecca Bompiani
16,996 PointsHi Niyamat-
You're getting that error because isEmpty() is not a method defined in your code.
For this challenge, what you'll want to do is alter the existing charge() method. We need to update the code with the following logic: while the battery is not fully charged (we can check this using our previous isFullyCharged() method), add one to mBarsCount
Try this:
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() {
// new/updated code goes here!
while(!isFullyCharged()){
mBarsCount++;
}
}
public boolean isBatteryEmpty() {
return mBarsCount == 0;
}
public boolean isFullyCharged() {
return mBarsCount == MAX_ENERGY_BARS;
}
}
Niyamat Almass
8,176 PointsThank you!!!!!!! I solve the challenge.
Jose Cortedano
409 PointsJose Cortedano
409 PointsNiyamat Almas, please take a look again. You are calling a method that does not exist in your code. You cannot boolean isEmpty if the method has nothing to (!). I think you meant to call isBatteryEmpty() not isEmpty. Good luck!