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 Increment and Decrement

Can't seem to figure out what I've done wrong regarding the shorthand way to increment the int variable lapsDriven.

Hi everyone,

After combing through the newly created int variable "lapsDriven", as well as the method "drive", I can't figure out why I keep getting this code challenge wrong. Could it be that I haven't assigned the "lapsDriven" variable the value of 1?

Thank you in advance for your help.

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;
  }

  public void charge() {
    barCount = MAX_BARS;
  }

  public boolean isBatteryEmpty() {
    return barCount == 0;
  }

  public boolean isFullyCharged() {
    return MAX_BARS == barCount;
  }

  private int lapsDriven;

  public void drive() {
   int lapsDriven += 1;
  }
}

1 Answer

pet
pet
10,908 Points

What Craig is referring to as short hand is

++

not

+=

good job though got stuck there too. :)

Pet,

Thank you so much for your quick response. I tried the ++ and it worked. I actually forgot about it after Craig's video lesson had ended lol.

pet
pet
10,908 Points

No problem Justyn. :)