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 trialDean Scelza
15,475 PointsIncredibly frustrated by this Incrementing Battery objective - code seems fine but fails - no errors on previewer.
my code:
public void charge() { while (!isFullyCharged()) { mBarsCount++; } }
I also tried: public boolean charge() { while (!isFullyCharged()) { mBarsCount++; } }
both fail - all previous forum questions indicate that this code should pass - please help, I've wasted over 3 hours on this already....
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 void charge() {
while (!isFullyCharged()) {
mBarsCount++;
}
}
public boolean isBatteryEmpty() {
return mBarsCount == 0;
}
public boolean isFullyCharged() {
return mBarsCount == MAX_ENERGY_BARS;
}
}
3 Answers
ALBERT QERIMI
49,872 PointsHMMM try to add my code on charge method andd you will pass it
Dean Scelza
15,475 Pointswell, not sure what you were referring to exactly, but i removed all other code relating to the charge method and it finally worked - super-frustrated by the waste of my entire morning on this objective, especially since i had the gist of it nailed from the get go - very disappointing, TreeHouse
ALBERT QERIMI
49,872 Pointspublic void charge() {
while (!isFullyCharged()) {
mBarsCount++;
}
}
Dean Scelza
15,475 Pointsa. that is IDENTICAL to the code I wrote - not sure how that is supposed to help...
b. BUMMER! There is a compiler error. Please click on preview to view your syntax errors! :clicks: TreeHouse returns a blank screen.
:(
anyone else.... .....please....?
ALBERT QERIMI
49,872 PointsTask was super easy you need to practice more somtimes not to try so hard like 3 hours in one method brbrbrbbrbrbr try to rewrite your code practice more read jave documention for example and Craig explained java courses very well try to rewatch videos all the best
Maya Angelica Gurgiolo
4,268 PointsMaya Angelica Gurgiolo
4,268 PointsHi, You have two methods called "charge":
public void charge() { mBarsCount = MAX_ENERGY_BARS; }
public void charge() { while (!isFullyCharged()) { mBarsCount++; } }
Try changing the new one you are making for the challenge to a different name. I don't know much about Java yet and I'm not sure about this, but you may also need to move the new method to the end of your code (since where the block is now you are using isFullyCharged before it's defined).
Hope this helps!