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

Harnessing the Power of Objects, completely stuck

I for the life of me cannot get it to work, tells me to make mBarCount public, if i do it tells me to make it unchangable.

GoKart.java
public class GoKart {
  public final int MAX_BARS = 8;
  private String mColor;
  private int mBarCount;

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

  public String getColor() {
    return mColor;
  } 
}

2 Answers

Isaiah Marin
Isaiah Marin
11,971 Points

Hey Charles, so I noticed you have forgotten to make your member variable, MAX_BARS static. From what I understand, this lets you access it from the class. Thus, try changing:

public final int MAX_BARS = 8;

to

public static final int MAX_BARS = 8;

Another Thing, don't know if it affects it but it asks for the specific name, "mBarsCount." So I'd recommend changing "mBarCount" to "mBarsCount" for this challenge.

I hope this helps.

I would suggest starting the challenge over. Then, look at this code for your example to follow. Connecting the challenge questions to the material covered in the lesson may be a good strategy throughout the course:

public class PezDispenser {
  public static final int MAX_PEZ = 12;
  private String mCharacterName;
  private int mPezCount;

  public PezDispenser(String characterName) {
    mCharacterName = characterName;
    mPezCount = 0;
  }

  public void load() {
    mPezCount = MAX_PEZ; 
  }

  public String getCharacterName() {
    return mCharacterName;
  }
}
  • Instead of MAX_PEZ, you are creating MAX_BARS
  • Instead of mPezCount, you are creating mBarsCount
  • Instead of a load method, you are creating a charge method