Java Java Objects Harnessing the Power of Objects Increment and Decrement

Evan Coakley
PRO
Evan Coakley
Pro Student 7,588 Points

I am missing something about incrementing

"In your newly created drive method, increment the new lapsDriven variable by 1. Use the incrementing shorthand to increase lapsDriven." That is the request. I'm not sure how to write out the code. I've tried lapsDriven += 1; I've tried return lapsDriven += 1;. Any ideas?

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

  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;
  }
  public boolean drive() {
      lapsDriven.isEqualTo(+=1)
   }
}

1 Answer

Hi Evan,

Try this:

public void drive() {
      lapsDriven++;
   }