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 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. :)