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

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.

No problem Justyn. :)