Java Java Objects Harnessing the Power of Objects Computed Properties

Tinashe Nyandoro
Tinashe Nyandoro
564 Points

Create a new public method named isBatteryEmpty that returns true if the battery has 0 bars remaining, and false otherwi

code still returns error after closing method.

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() {
    if (barCount == 0) {
    return true;
    } else {
    return false;
   }
 }
}

1 Answer

Luke Maslany
Luke Maslany
3,534 Points

I think you need to add the isBatteryEmpty() method inside the GoKart class.

Luke Maslany
Luke Maslany
3,534 Points
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() {
    if (barCount == 0) {
      return true;
    } else {
      return false;
    }
  }

}