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 Methods and Constants

Matthew Denton
Matthew Denton
598 Points

Add a method named charge. It should be public and return nothing. When called it should set mBarsCount to the value...

Hi Guys

I've added the Method named "charge" but i'm not sure what i'm doing wrong. Please advise.

Thanks in advance

GoKart.java
public class GoKart {
  public static final int MBARS_COUNT = 8;
  private int mBarsCount;
 public void charge() {
  mBarsCount = charge;
  }
    private String mColor;

  public GoKart(String color) {
    mColor = color;
  }

  public String getColor() {
    return mColor;
  } 
}

1 Answer

Dan Johnson
Dan Johnson
40,532 Points

The charge method is expected to set mBarsCount to its max count, which is MBARS_COUNT:

  public void charge() {
    mBarsCount = MBARS_COUNT; 
  }

There is no local or member variable named charged defined so you can't assign it to anything.

Matthew Denton
Matthew Denton
598 Points

Awesome, thanks for your help Dan