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

Java Incrementing and Decrementing

What in the world am I missing? I need the very last step apperently. Please help!!!

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() {
   charge(MAX_ENERGY_BARS);
  }

   public void charge(int barsAmount) {
    mBarsCount += barsAmount;
   }
  public boolean isBatteryEmpty() {
    return mBarsCount == 0;
  }

  public boolean isFullyCharged() {
     boolean isFullyCharged = false;
    if (!isFullyCharged()) {
      mBarsCount--;
   isFullyCharged = true;
    }

        while (!isFullyCharged()) {
       mBarsCount++;
          return isFullyCharged;
      }
  }           
  }

Hi Sara,

You need to adjust the charge() method rather than the isFullyCharged() method.

Use the charge method to use the isFullyCharged() method to check whether it is fully charged, and have it increment the bars mBarsCount while it is not.

If this hint doesn't help, I'll post my solution.

Best, Alex

1 Answer

rydavim
rydavim
18,814 Points

Sorry you didn't find the earlier answer helpful!

You want to be editing the charge method. You don't need to change any other methods or properties.

// You want the charge() method to charge the battery of the kart, only if it is not fully charged.
 public void charge() {
    while (!isFullyCharged()) {  // while the kart is not fully charged...
      mBarsCount++;  // increment mBarsCount
    }
  }