Java Java Objects Harnessing the Power of Objects Increment and Decrement

Not sure

not sure how to do the decrement. pls 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 (){
  lapsDriven++;
  return barCount == lapsDriven;  
  }

}

1 Answer

Samuel Ferree
Samuel Ferree
31,714 Points

Using the -- operator in your drive method. You also don't need to return anything

public void drive () {
  lapsDriven++;
  barCount--;
}