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 trialMUZ140564 Kudakwashe Jena
4,895 PointsOkay, so let's use our new isFullyCharged helper method to change our implementation details of the charge method. Let's
i dont know where am going wrong.My u help please.
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() {
while (! isFullyCharged() ) {
mBarsCount++;
}
}
public boolean isBatteryEmpty() {
return mBarsCount == 0;
}
public boolean isFullyCharged() {
while (!isBatteryEmpty()) {
mBarsCount ++;
isFullyCharged = false;
}
return mBarsCount == MAX_ENERGY_BARS;
}
}
5 Answers
Jess Sanders
12,086 Pointspublic boolean isFullyCharged() {
return mBarsCount == MAX_ENERGY_BARS;
}
Change isFullyCharged back to how it was originally, from your previous challenge.
Steve Hunter
57,712 PointsCraig Dennis
Treehouse TeacherI think you should leave the isFullyCharged
method alone, and just use charge
Edwin Amaya
Courses Plus Student 809 Pointsi think you are setting battery as empty instead of checking if its empty so everytime the isFullyCharged methods checks to see if it its empty it is being actually set to empty and thus will never be full
public boolean isBatteryEmpty() {
return mBarsCount == 0; //
}
ps to the admins: i dont know how to enter "code" i used the back ticks like the markdown sheet said but it doesnt format the code
Craig Dennis
Treehouse TeacherHey Edwin,
I fixed your answer and I did it by adding 3 back ticks on a line followed by the word java (If you edit it you can see it) and then followed it with 3 backticks.
Thanks!
Edwin Amaya
Courses Plus Student 809 Pointsahh I see! said the blind man as he headed out to sea! thanks guys.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsHi Edwin,
The backticks work OK on their own but are much better if you stipulate the language after the first three.
Make sure you're not using back slashes or single quotes too. I'll reformat your comment now to demonstrate, go in and edit it after I have done that to see the markup displayed.
Steve.
[edit] Craig beat me to it!!