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

Something seems to be wrong with your method. Double check you are calling the original drive method and passing in 1.

this is the challenge task Im having trouble with....

I have added a method (drive) that defines a parameter (laps). These high powered GoKarts use 1 energy bar off their battery each lap. Using method signatures, add a new method called drive that performs just 1 lap and takes no arguments.

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(int laps) {
    // Other driving code omitted for clarity purposes
    mBarsCount -= laps;
  }
  public void drive(){
   drive(mBarsCount); 
  }
  public void charge() {
    while (!isFullyCharged()) {
      mBarsCount++;
    }
  }

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

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

}

1 Answer

Jacob Bergdahl
Jacob Bergdahl
29,119 Points

Like the hint is telling you: you're supposed to add 1 as an argument, not mBarsCount :) You're supposed to send in the number of laps, not the bars. Look at the implementation of drive(int laps) :)

Yeah... that is just where I was when I decided to ask for help.... literaly just stumbled over what happened to be a lucky guess before you answered..... but still in the interest of best understanding I thought it would be laps(the answer) not drive.... if you can tell me why its not that would help A LOT. THANKS

Jacob Bergdahl
Jacob Bergdahl
29,119 Points

I don't understand your question. Could you elaborate? You're doing method chaining. The method drive has int laps as parameter. You want this method to do all the work. If you look inside that method, you can see that it says mBarsCount -= laps; -- in other words, sending in mBarsCount makes no sense.

sorry for the confusion. basically I'm just curious as to why the answer is drive(blank) instead of laps(blank), but I think I get it now thanks again for the help

Jacob Bergdahl
Jacob Bergdahl
29,119 Points

Because you're driving. There might be other functionality inside the method besides just going around a lap. And laps() doesn't really say much either.