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 trialMUZ141069 Carlson Chibaya
462 Pointsim lost
where am i getting it wrong?
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 void charge() {
while(!isFullyCharged()) {
mBarsCount ++;
}
}
}
MUZ141069 Carlson Chibaya
462 PointsGrigorij Schleifer u are the best, thank u thank u
3 Answers
metzu
5,907 PointsThere's only one problem, charge method is already define. change it's implementation. don't make another charge method. :)
Grigorij Schleifer
10,365 PointsHi Carlson,
you are soooo close ...
In this challenge you donΒ΄t need to change the isFullyCharge method at all because this method is already good to go. Use it inside the charge method to proof the charge state of your GoKart. And you have the working code already:) but in the wrong method.
take this:
while(!isFullyCharged()) {
mBarsCount ++;
}
and paste it intoo the existing charge method. And it should be great :)
So Inside your charge method :
public void charge() {
while (!isFullyCharged()) {
// while not fully charged please increment the mBarsCount
//
mBarsCount++;
}
}
You can delete "mBarsCount = MAX_ENERGY_BARS" inside charge() because you set the mBarsCount if your GoKart is not FullyCharged :)
Let us know if you need more help and donΒ΄t give up
Grigorij
MUZ141069 Carlson Chibaya
462 PointsHi Grigorij, the link u sent me cannot open i dont knw why it keeps saying page not found
Grigorij Schleifer
10,365 PointsI know, I am writing a more complex answer. If you want to use the link, please delete the last 4 characters
MUZ141069 Carlson Chibaya
462 Pointsit still asked me to add a while statement please help im lost!
Kevin Faust
15,353 PointsWhat Grigorij wrote worked for me. Just refresh your page, and change the default charge method to what he wrote.
Grigorij Schleifer
10,365 PointsHi Carlson,
glad to help you :)
Mark it as best answer, so other Java-Warriors can use it for their research
Grigorij
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHey ho,
here is the code that should work fine !
Grigorij