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

Hayden Bohlen
Hayden Bohlen
571 Points

Could anyone help me pass this challenge. I am not certain what is wrong with the code.

The error message reads that mBars needs to be set private but when i do the error says that mBars needs to private not entire sure. I would appreciate the help

GoKart.java
public class GoKart {
  public static final int MAX_BARS = 8;
  private String mColor;
  public int mBars;
  public GoKart(String color) {
    mColor = color;
    mBars = 0;
  }

  public String getColor() {
    return mColor;
  } 
}

2 Answers

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hello Hayden,

You're close on this. I believe they want the variable to be called mBarsCount, just declare that as private when you make it and you already did a good job setting it to 0 in the constructor, so that should sort things out.

Let me know if this doesn't help.

Hi Rob,

Just wanted to say it's great to see you get a mod tag :)

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