Java Java Objects Harnessing the Power of Objects Overload Methods

Blessed Mupatsi
Blessed Mupatsi
764 Points

drive method

Modify the drive method to define a parameter of how many laps should be driven. Update the method body to handle the new parameter.

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 void drive() {
    lapsDriven++;
    barCount--;
  }
}
Steven Parker
Steven Parker
201,997 Points

This is the provided code, unchanged. Show what you've done to it.