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 trialPeter Kurkowski
595 PointsI cant figure out how to set isFullyCharged method to true if charge is full.
I'm really lost here, i cant figure out to have this method return true when charge is equal to max_bars.
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 String getColor() {
return mColor;
}
public void charge() {
mBarsCount = MAX_BARS;
}
public boolean isBatteryEmpty() {
return mBarsCount == 0;
}
public boolean isFullyCharged() {
return mBarsCount = MAX_BARS;
}
}
3 Answers
Henrik Hansen
23,176 Points return mBarsCount = MAX_BARS;
What you are doing here is setting the value of mBarsCount. You want to test if it is equal instead.
Paul Ryan
4,584 Pointspublic class GoKart {
public static final int MAX_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_BARS;
}
public boolean isBatteryEmpty() {
return mBarsCount == 0;
}
public boolean isFullyCharged() {
return mBarsCount == MAX_BARS;
}
}
Not sure of what is expected but I assume the method you mean is isFullyCharged(). so if mBarsCount has the same value as MAX_BARS then it is fully charged
Mark Miller
45,831 PointsYou must use a test! To get the Boolean data type returned, test for equality with the double equals sign == in between the variable and the constant, after the word 'return.' That is the only thing you need to change - adding an extra equals sign will make it a test for equality, returning a true or false. Remember that the single equals sign is the assignment operator, not a test operator.
Peter Kurkowski
595 PointsPeter Kurkowski
595 Pointswhat i had to do was:
return mBarsCount == 8;