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

Jonathan Hector
Jonathan Hector
5,225 Points

I think the instructions are wrongly put but still can't move on.

Please some help. I'm not sure I got the whole question.

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() {
   if(!isFullyCharged())
     isFullyCharged = true;
    mBarsCount = MAX_ENERGY_BARS;
  }

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

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

}

2 Answers

Blake Larson
Blake Larson
13,014 Points
public void charge() {
   if(!isFullyCharged())
     isFullyCharged = true;
    mBarsCount = MAX_ENERGY_BARS;
  }

This challenge wants you to complete the charge method so that while it is not fully charged (The "while" loop instead of "if") you continue to increment mBarsCount. Meaning every time that while statement is true, it will enter into the loop and increment by 1 bar. Once full it will break out of the loop and the method is complete.

Another way of formulating the instructions: Implement a more realistic charge method. You won't come across a charger which gets your smartphone battery from 0 to a 100 percent instantly. Change your current implementation (basically the way you solved it before you got somd new tools) of the charge method so that the battery will charge one bar at a time. So the method should check if the battery is full with the isFullyCharged method you created earlier and if the condition is not (!) true raise your bar count by one :) Put it all into a while loop and you are basically good to go :)