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

Amit Dhamankar
Amit Dhamankar
4,163 Points

Why this code is not working?

I have passed the value 1 in the new drive method and decreased the value of mBarsCount by 1. as it is given in the question that it does not accept any parameters. And the decremented the count by 1. still I am getting a bummer. please help

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 int drive(1) {
    mBarsCount = mBarsCount - 1;
    return mBarsCount;
  }

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

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

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

}

3 Answers

Amit,

I've not taken this course so I'm just reading the code and deducing from that.

I see you have 2 "drive" methods, one is to return an in and the other void. Is there a reason for 2 of them? Or could that be causing the error? Do you need a setDrive and getDrive methods instead?

Hope this helps.

Ron

Hi Amit - I just looked at the challenge question, and I think the issue is that the new drive method isn't supposed to take any arguments but you're passing in a 1 as an argument.

Glen Hayes
Glen Hayes
5,798 Points

You're nearly there, you need to use the drive function from the first function as a method in the second function and then pass that method the argument.