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

Stuck and cornfused.

Hello I am frustrated regarding what Craig is even asking us to do in this question. Knowing just what we know up to this part I dont know exactly what he wants me to give him.

So I see that he listed out the method drive the defines laps. Then there is a line that goKarts use 1 energy bar off their battery each lap.

His exact question is "Using method signatures, add a new method called drive that performs just 1 lap and takes no arguments.

My first initial response is didnt he already list the method drive? The first sentence is "I have added a method drive". So when I try to add the method I get a wonderful error. The next part is involves adding some code that performs just 1 lap and takes no arguments. Not super clear to me. (Partly why I get so confused is he loves to list all all this other code here that really doesn't have anything to do with the problem.)

I have no idea what he wants from the laps part. I dont recall any of the videos were we learned how to write a statement that captures the English definition of "performs". Is he asking for something that continues to add up how many laps have been completed? Large communication breakdown for me. At least for me this is very general as to what he wants especially since there is virtually only 1 write answer.

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 charge() {
    while (!isFullyCharged()) {
      mBarsCount++;
    }
  }

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

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




}

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

You have a drive() method that takes the number of laps you want to do. The challenge is asking you to write a 2nd drive() method that doesn't take any number but will drive for 1 lap. This is almost the same as the two load() methods in the previous video where one adds a certain number of pez to the dispenser and the other fills it.