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

when calling your method the mBarsCount did not decrement by 1 as expected.

i even added a class private int mLapsCount and still dont get it plz anyone ?

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

  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 () {
    mLapsCount += 1;
  }

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

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

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

}

1 Answer

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

You don't actually have to do much here. Let me explain

See, you have a method called drive that takes a certain number of laps, and decrements the energy per lap.

You must create another method called drive with a different method signature.

Since all drive does is decrement the bar count. It doesn't makes sense to give it more arguments than the original drive. So it would make sense to just give it none. That way the method signatures are different.

Although, our first drive method, the one that takes an argument. It does all the work for us.

Inside my drive method. I am just going to call the drive method that takes a number of laps, and just pass it 1. Than the bar count goes down by 1 for I told he car to only drive 1 lap.

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

Does this make sense? if not, let me know and I will try and answer your other questions in regards to this.

Thanks!

i already tried that last time but it told me this :" Remember that you should call the existing drive method and pass in the default parameter of 1 . Otherwise you would have to rewrite all that ( omitted) code. And i did try it again i thought i did something wrong the first time and thx as lot for responding fast thx a lot mate !

it worked i refresh the page and i did the work hahahaha thx a lot you saved me man ! without you i would still be stuck !!!! thx again .