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

Brandon Wash
PLUS
Brandon Wash
Courses Plus Student 1,186 Points

How to call on the method?

Finally, let's add a method named charge. It should be public and return nothing. When called it should set mBarsCount to the value of the constant you declared in Task 1. What did I do wrong?

GoKart.java
public class GoKart {
  public static final int MAX_BAR = 8;
  private String mColor;
  private int mBarsCount;


  public GoKart(String color) {
    mColor = color;
    mBarsCount = 0;
  }
  public void bar() {
  mBarsCount = MAX_BAR;
  }
  public String getColor() {
    return mColor;
  } 
}

2 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Brandon,

The challenge is asking you to create a public method named "charge" but it seems like your new method is named bar. Rename the bar method to charge and you should be good to go.

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