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 Overload Methods

I m not understanding what this question is trying to say!..

please help me and send me the solution of what code it wants to be written.

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() {
    lapsDriven++;
    MAX_BARS--;

  }
}

1 Answer

I'll give you the answer but you'll also need to understand what the problem is.

It wants you to give the drive method an argument of how many laps the GoKart rode. So, in the method drive(), you need to add a parameter. This is a number so it's a int parameter, an integer.

public void drive(int lapsDrivenn) {

Since you give it an parameter/argument, you need to use it. Instead of going lap by lap, it now uses the integer you gave to it, to know how many laps the GoKart did. Hence we will up the amount of laps that were driven, lapsDriven with our integer. Then we also need to change the progressbar so the player knows how many laps it has to go. So, we also have to lower the counter of that bar, barCount with the amount of laps we drove.

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