Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Harnessing the Power of Objects Helper Methods

Peter Kurkowski
Peter Kurkowski
595 Points

I cant figure out how to set isFullyCharged method to true if charge is full.

I'm really lost here, i cant figure out to have this method return true when charge is equal to max_bars.

GoKart.java
public class GoKart {
  public static final int MAX_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_BARS;
  }

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

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

3 Answers

Henrik Hansen
Henrik Hansen
23,176 Points
 return mBarsCount = MAX_BARS;

What you are doing here is setting the value of mBarsCount. You want to test if it is equal instead.

Peter Kurkowski
Peter Kurkowski
595 Points

what i had to do was:

return mBarsCount == 8;

Paul Ryan
Paul Ryan
4,584 Points
public class GoKart {
  public static final int MAX_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_BARS;
  }

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

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

Not sure of what is expected but I assume the method you mean is isFullyCharged(). so if mBarsCount has the same value as MAX_BARS then it is fully charged

Mark Miller
Mark Miller
45,831 Points

You must use a test! To get the Boolean data type returned, test for equality with the double equals sign == in between the variable and the constant, after the word 'return.' That is the only thing you need to change - adding an extra equals sign will make it a test for equality, returning a true or false. Remember that the single equals sign is the assignment operator, not a test operator.