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

can anybody assist me with this code.

i need to know what to return in my boolean method

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() {

    while(!isFullyCharged()){

    mBarsCount++;
   return mBarsCount;


    }
  }

}

3 Answers

aakarshrestha
aakarshrestha
6,509 Points

Do this:

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() {
    while(!isFullyCharged()) {
         mBarsCount++;
    }
  }

  public boolean isBatteryEmpty() {
    return mBarsCount == 0;
  }

  public boolean isFullyCharged() {
    return mBarsCount == MAX_ENERGY_BARS;
    }
  }

}

Hope it helps!

Happy coding!

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I think there may be a problem in your understanding of the instructions. You're not supposed to change the isFullyCharged method at all. It wants you to modify the charge method to use the value returned by isFullyCharged method.

Ok, the max energy bars are 8. But let's say you're down to 2 and want to recharge it using the charge method. What we want to do is charge until the value returned by isFullyCharged is true. I hope this helps, but if you need further clarification let us know! :sparkles:

thank you so much for your help

aakarshrestha
aakarshrestha
6,509 Points

if it worked for you, please mark the answer the best. You get your problem solved and i will get my points as reward for helping!

Happy coding!