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

Having trouble with method signatures

I can't figure out how to assign the method to this. I put drive(1) thinking that enough parameters were defined but apparently not. Can anyone help me understand how this is done? I feel this particular video lacked something to show me the translation between the 2 scenarios.

Thanks a bunch!

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;

    drive(1);


  }


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

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

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

}

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Greg;

I wrote a rather long winded explanation on this topic here. Take a look and if you are still stuck, please post back. This is an important topic and having a good understanding of it is important going forward.

Happy coding,

Ken

Yes, indeed, Ken...thank you. This helps significantly but I think I need to read a little more on methods and classes before moving to the next step because I don't feel I totally grasp it. Thank you for the quick response. Also, should I be asking these questions differently?

Thanks, Greg

Ken Alger
Ken Alger
Treehouse Teacher

Greg;

I think you are right on track for the types of and way in which you are asking questions. It is great that you are doing so early on to make sure you have a solid foundation of knowledge.

Happy coding,

Ken