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

Robert Roberson
PLUS
Robert Roberson
Courses Plus Student 8,401 Points

I thought for sure I was right but clearly I am not.

Really don't know what to do more with this.

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() {
    // Other driving code omitted for clarity purposes
    drive(MAX_BARS);
  }
  public void drive(int laps) {
    mBarsCount -= laps;

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

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

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

}

1 Answer

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) {

    // to start this method 

    mBarsCount -= laps;
  }

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

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

  public boolean isFullyCharged() {
    return mBarsCount == MAX_BARS;
  }
  public void drive() {
    // we use this
    drive(1);
  }

}

Important to know is just:

  public void drive(int laps) {

    // ....to start this method 
    // to do this "lap-thing"
    mBarsCount -= laps;
  }

  public void drive() {
    // we use this....
    // starts the drive methods with the argument and give it "1" as an argument
    drive(1);
  }
Robert Roberson
Robert Roberson
Courses Plus Student 8,401 Points

Thank you, Tobias. But that is not at all what I learned in the video.

Robert Roberson
Robert Roberson
Courses Plus Student 8,401 Points

Your answer was great. But why does he drone on in the pez video thing about something entirely different, if that is not what we are going to do in the exercise?