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 trial

Java Java Objects (Retired) Harnessing the Power of Objects Incrementing

Still not working out... going to take a break and come back later

The error wants the call to come from the "while" ... but it's not working out...still. I am taking break and coming back later....

GoKart.java
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() {
   boolean isCharging = false;
    while(isBatteryEmpty()){
      mBarsCount++;
      isCharging = true;
    }
    while (!isCharging) {
      mBarsCount++;
    } return isCharging;

  }

}

2 Answers

Geovanie Alvarez
Geovanie Alvarez
21,500 Points

You need to do the while loop inside of the charge method not in the isFullyCharged

public void charge() {
    while(!isFullyCharged()){
      mBarsCount++;
    }
 }

and leave the isFullyCharged

public boolean isFullyCharged() {
    return mBarsCount == MAX_ENERGY_BARS;
 }
Peng Liu
Peng Liu
Courses Plus Student 14,273 Points

Alvarez is right, before put these codes in, you need to reset the code to default(it gives you this option alongside check work on the challenge page).

Peng

Thanks, man but that was handled yesterday morning...... Peace...