Java Java Objects Harnessing the Power of Objects Increment and Decrement

NAJEEBULLAH KHAN
NAJEEBULLAH KHAN
2,967 Points

it keeps on saying task 1 not passing even though i only made a public void int drive;

why

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 int drive()
}

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there! The reason it is saying that "Task 1 is no longer passing" is because you've introduced a syntax error in your code which results in a compiler error. The code can no longer be compiled at this point. A method may only have one return type. But your method has two return types. You've said void int. Both void and int are data types. The void is a special data type which means essentially "nothing". At this point, you're trying to tell the method that it will return both an int and nothing at the same time.

The challenge requests a return type of void, so you can safely remove the int. Also, your function is missing the open and closed curly braces which will also cause a compiler error. Lastly, the challenge is asking you to increment the number of laps driven inside the body of the method, but currently, your method has no body.

  public void drive() {
      lapsDriven++;
    }

This creates a method named drive that returns nothing. In the body of the method, we increment the number of laps driven by one using the shorthand discussed in the video.

Hope this helps! :sparkles: