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 Harnessing the Power of Objects Changing State

Khairi Ismail
Khairi Ismail
869 Points

How do I set barCount to MaxBars?

I got this message and I don't understand what it means. Make sure you set the GoKart's barCount to MAX_BARS in the charge method

GoKart.java
class GoKart {
  public static final int MAX_BARS = 8;
  private int barCount;
  private String color;

  public GoKart(String color) {
    this.color = color;
  }

  public String getColor() {
    return color;
  }

  public void charge(int MAX_BARS, int barCount) {    
    barCount = Max_BARS;
  }
}

1 Answer

Zachary Kaufman
Zachary Kaufman
1,463 Points

You're close, get rid of everything in the () in the charge method. What you are doing is making a new variable called barCount and a new constant called MAX_BARS and ignoring the ones already there. Which means that inside the {} they are affecting the variable/constant from inside your () and not the ones declared on lines 2 and 3. I hope this helps.

Khairi Ismail
Khairi Ismail
869 Points

Thank you for the reply. I have fixed it. I forgot to use caps lock for MAX_BARS. Instead I used Max_BARS.