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

Fatimah Ghazal
Fatimah Ghazal
1,848 Points

hi, can you help me with the incrementing quiz

i reached a point where it says : "Something fishy is going on, please only refactor the charge method. and i don't understand what does it mean.

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

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



}

1 Answer

andren
andren
28,558 Points

It means that you modified something different from what the challenge asked you to. The challenge is to refactor the drive method, you have changed the code in the isBatteryEmpty method instead. Which is not what the task asked you to do.

The while loop you have written is actually completely right, the only problem is that it is in the wrong method, if you cut your while loop out of the isBatteryEmpty method and paste it into the drive method (replacing the line that is currently there) then your code will pass the challenge.