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

GoKart barCount

Hi, I'm confused I have rewatched the video multiple times but still have trouble grasping the concepts a solution with an explanation on why is greatly appreciated.

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

  }

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

  }

  public String getColor() {
    return color;
  }
  private barCount() {}

}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Samuel Zink! It looks like you were initially off to a good start, but then a stray closing curly brace got in the way }. Your class is being closed prematurely. I think in your effort to figure out the issue you then made a private method named barCount() which isn't what they're looking for on the first step.

You have:

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

  } // Woops! Your class ends here

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

  }

  public String getColor() {
    return color;
  }
  private barCount() {}

}

But you needed:

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


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

  public String getColor() {
    return color;
  }
}

Note that I removed the runaway closing curly brace and the bottom private barcount() {}. Then it passes the first step of the challenge.

Hope this helps! :sparkles: