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

Joseph Bennett
Joseph Bennett
529 Points

I am totally confused on the challenge. it displays something about not decrementing but I have.

Double check you are calling the original drive method and passing in 1.

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


  }

Very confused

Hi Joseph,

I add markdown to help make the code more readable. If you're curious about how to add markdown like this on your own, checkout this thread on posting code to the forum . Also, there is a link at the bottom called Markdown Cheatsheet that gives a brief overview of how to add markdown to your posts.

Cheers!

3 Answers

The challenge is expecting you to use the new technique you learned: method signatures. You already had a drive method that subtracts mBarsCount. Now you need to construct a new method that takes no parameters and passes in the value of 1 to the old drive method. By doing so, we avoid violating the D-R-Y principle.

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

public void drive(int laps) {
     mBarsCount -= laps;
}
Joseph Bennett
Joseph Bennett
529 Points

I swear on every part I get stuck on I over complicate it. Thank you.

Alvaro Gutierrez
Alvaro Gutierrez
1,471 Points

I am having problems with this same task. I also am getting "Something seems to be wrong with your method. Double check you are calling the original drive method and passing in 1." Here is my code:

  public void drive() {
     drive(mBarsCount);
  }
  public void drive(int laps) {
    // Other driving code omitted for clarity purposes
    mBarsCount -= laps;
    ```
luis martinez
luis martinez
2,480 Points

what i did for the drive method was put

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

check if it works

luis martinez
luis martinez
2,480 Points

if you have problems with the next challenge look at this link https://teamtreehouse.com/forum/illegalargumentsexception

Jake Fleming
STAFF
Jake Fleming
Treehouse Guest Teacher

For those of you still confused, here's what your code should look like:

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() {
    drive(1);
  }

  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;
  }

}

Thank you Jake. I'm still waiting for the lightbulb over my head to click on. One day, one day.