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

can you help me?

.

GoKart.java
public class GoKart {
  private String mColor;

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

  public String getColor() {
    return mColor;
  } 
}

2 Answers

I see you need a little help with the challenge, but your question is pretty vague. Without giving away all the answer, I left an outline for what we learned in the lesson as applied to this problem below. Please let me know if it helps by rating it!

Happy coding! Nicolas

public class GoKart {
  private String mColor;
  // This is where we initialize values, like has been done with mColor above
  // Constants, unlike member variables, set there values here (they are final values)
  // CONSTANTS_ARE_NAMED_LIKE_THIS

  public GoKart(String color) {
    mColor = color;
    //this part is the constructor, which has the same name as the class
    //this is where you set values at the beginning of the program
  }

  public String getColor() {
    return mColor;
  } 

  public void aMethodThatReturnsNoValue() {
    // How can we add power to this gokart?
  }
}

It may be helpful to connect the challenge with the lesson. Look at this code for your example to follow:

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