Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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: