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 trialAhkeem Lang
16,358 PointsCreating a helper method
I'm currently on the second part of the challenge task and I'm being asked to create a helper method called isFullyCharged. I created it but I'm not sure where I'm suppose to go from here... Help please?!
public 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() {
return mBarsCount == 0;
}
public boolean isFullyCharged(isBatteryEmpty()) {
return mBarsCount;
}
public String getColor() {
return mColor;
}
public void charge() {
mBarsCount = MAX_BARS;
}
}
3 Answers
markmneimneh
14,132 PointsHello
your isFullyCharge helper is incorrect
public boolean isFullyCharged(isBatteryEmpty()) { return mBarsCount; }
The method should return a boolean, but you are returning int instead.
I suspect you want to do:
public boolean isFullyCharged(isBatteryEmpty()) { charge(); return true; }
Basically, you want to charge the battery ans then return a true as in: yep, the battery is now full charged.
Hope this helps. if this answers your question, please mark the question as answered
Thanks
Ahkeem Lang
16,358 PointsHey there! I tried out your solution but when I give it a shot I end up with multiple syntax errors.
The answer was, public boolean isFullyCharged() { return mBarsCount == 8; }
But thanks!
markmneimneh
14,132 PointsHi
I am not taking this course per se; I just noticed the the fact the originally you were returning an int when a boolean is expected. your fix is correct, you are now returning a boolean.
Thanks
Ahkeem Lang
16,358 PointsAh for sure! Thank you :D
Ahkeem Lang
16,358 PointsAhkeem Lang
16,358 PointsAh Thank you!