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 Deincrementing Challenge

I need help please!!! I don't know what the while statement needs and what return is wanted.

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 wasCharged = false;
    if (!isFullyCharged()) {
      wasCharged = true;
    return wasCharged;

  while (isFullyCharged()) {

1 Answer

18,814 Points

You want to change the charge() method code. Instead of setting mBarsCount equal to MAX_ENERGY_BARS, you want to check to see if the kart is fully charged using the isFullyCharged method. If the kart is not fully charged, you want to increment the battery bars by one. You should do this using a while loop.

public void charge() {  // You want to edit this method.
      // mBarsCount = MAX_ENERGY_BARS;  // Nope, don't need this anymore!
      // Start a while loop, checking to see if isFullyCharged() is false. Don't forget the '!'
      // Inside the while loop, increment mBarsCount by one.

Let me know if you'd like more of a hint. :)