Java Java Objects Harnessing the Power of Objects Increment and Decrement

Task 1 no longer passing

After writing the code to increase laps by 1, task 1 no longer passes. Please help & thanks in advance.

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

  public void String drive() {
   return lapsDriven=+1;
  }

  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;
  }
}
David Moody
David Moody
19,302 Points

In this case you made the void function take a String. If it is void, it returns nothing and you cannot put String next to void.

So, delete String from the phrase "public void String drive()", and it should work. You can use a different incrementing operator too, like this:

public void drive() { lapsDriven++; }

@David Moody That makes sense! Sadly it still doesn't seem to work.

David Moody
David Moody
19,302 Points

Did you change your incrementing operator too? Isn't the proper incrementing either ++ or +=1 instead of the order you have it in? (I ran my code through the challenge, and it worked for me. You must be leaving out a semicolon or putting the increment operator down slightly off or something minor. See what line they point to for your error.)