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 (Retired) Harnessing the Power of Objects Method Signatures

Michael LaCroix
Michael LaCroix
5,828 Points

Call existing method

I can't figure out how to class the existing drive method. I've been trying to glean it from the video, but what Craig does to call the new load method doesn't make any sense to me.

I'm also confused by some conflicting directions. The challenge says to make it go just 1 lap, but I got some 'help' when I ran the code and it said to pass through the existing default parameter of 1. How the heck am I supposed to know that's the default parameter? I thought that's what I was trying to code in -> just 1 lap. Very confused.

GoKart.java
public class GoKart {
  public static final int MAX_BARS = 8;
  private String mColor;
  private int mBarsCount;

  public GoKart(String color) {
    mColor = color;
    mBarsCount = 0;
  }

  public String getColor() {
    return mColor;
  }

public void drive(){
    mBarsCount--;
    }

  public void drive(int laps) {
    // Other driving code omitted for clarity purposes
    mBarsCount -= laps;
  }

  public void charge() {
    while (!isFullyCharged()) {
      mBarsCount++;
    }
  }

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

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

}

1 Answer

Stephen Bone
Stephen Bone
12,359 Points

Hi Michael

You're nearly there. What the challenge expects is to call the existing drive method (which expects an int value) so that you aren't repeating code (remember DRY) although I know your code is slightly different anyway.

So it expects you to create a new method like:

public void drive() {
    drive(1);
  }

Hope it helps!

Stephen