Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Harnessing the Power of Objects Increment and Decrement

Ricardo Brito
Ricardo Brito
469 Points

I'm supposed to use a Boolean here?

To answer that quiz I had insert the following: public boolean drive() { if (!isFullyCharged()) { lapsDriven++; barCount = true; } }

But I keep getting: "Drive shouldn't return anything so the return type should be void"

Should I put something like: " return drive (void): "?

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 drive() {
    if (!isFullyCharged()) {
      lapsDriven++;
      barCount = true;
    }
  }

  public boolean isBatteryEmpty() {
    return barCount == 0;
  }

  public boolean isFullyCharged() {
    return MAX_BARS == barCount;
  }
}

2 Answers

Steven Turner
Steven Turner
20,146 Points

Drive shouldn't be returning anything. The Drive Method should be adding how many laps you have driven and decreasing your battery life(the barCount).

barCount is a int variable so you can't set it to a boolean.

Fahad Mutair
Fahad Mutair
10,359 Points

Yes, Drive should be Void type

public void drive() {
      lapsDriven++;
      barCount--;
  }