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 trialLyndsi Barfield
633 PointsEvery time I attempt to complete the second task, it tells me the first task is no longer correct even though it was.
The first task told me it was correct but every time I attempt the second task it changes its mind and tells me the first task is no longer correct.
class GoKart {
public static final int MAX_BARS = 8;
private String color;
private int barCount;
public GoKart(String color) {
this.color = color;
}
public void charge() {
barCount = MAX_BARS;
}
public boolean isBatteryEmpty() {
return barCount == 0;
}
public boolean isFullyCharged() {
barCount == MAX_BARS;
}
public String getColor() {
return color;
}
}
1 Answer
John Anselmo
Courses Plus Student 2,281 PointsLyndsi,
I looked over your code and noticed something in the isFullyCharged()
method. You forgot to put return
before barCount == MAX_BARS;
You just put the same code from the charge()
method. Try that, and it should work.
The reason why it said that task 1 is not working, I'm assuming, is because they are running some sort of unit test on your code, and your isFullyCharged()
method kept resetting barCount
to 8, which is not what the isBatteryEmpty()
test was looking for. So jut go ahead and add return
and you should be fine!
Hope this helped!