Java Java Objects Harnessing the Power of Objects Overload Methods

Create a new method named drive that accepts no arguments.

It should call the newer drive method passing in a 1 for the default.

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 (int laps) {
    lapsDriven+=8;
    barCount-=0;
   }
    public int drive {
    lapsDrive+=8;
    barCount-=0;
  }
 }

1 Answer

Zachary Kaufman
Zachary Kaufman
1,462 Points

Your drive method needs to have (), as all methods do.

Also drive shouldn't return an integer, it is just like the first drive method except it takes no arguments, so...

public void drive() {}

and it also says the new drive method should CALL the old drive method. This does not mean copy and paste the old drive methods code inside the new one, just call the old drive by doing...

public void drive() {
     drive(1);
}

Java can tell which method you are calling based on the arguments you passed. The new drive method just allows the user to have a default of one lap. Your final answer should be the code above. I hope this helps.