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 Harnessing the Power of Objects Overload Methods

Daniels Ilori
Daniels Ilori
538 Points

On the topic method overloading!

"Create a new method named drive that accepts no arguments. It should call the newer drive method passing in a 1 for the default."

The above instruction is what I am currently stuck with, this is either because I don't understand the question properly or I don't just know how to solve the task beforehand. I need a coding angel out there to put me back on track please. Thanks!

GoKart.java
class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private int barCount;
  private int lapsDriven;

  public GoKart(String color) {
    this.color = color;
  }

  public String getColor() {
    return color;
  }
  public void charge() {
    barCount = MAX_BARS;
  }

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

  public boolean isFullyCharged() {
    return MAX_BARS == barCount;
  }
  public void drive() {
    return int lapsDriven = 1;
  }
  public void drive(int lapsDriven) {
    lapsDriven += lapsDriven;
    barCount-= barCount;
  }

}

3 Answers

Hi Daniels,

You've got this!

In your new drive method - just call the other drive method, passing 1 into it. You've got the method skeleton correct; it takes no parameters and returns nothing but inside just call the other drive method and put 1 inside the parentheses.

Let me know how you get on.

Steve.

Daniels Ilori
Daniels Ilori
538 Points

Hi, Steve! Thanks for your prompt guide. I was just about deleting the question since I was able to complete the task already. It's actually freeing to know there are few ones out there who have got your back on this journey. :) Thanks again!!

Don't delete posts - they do help others. And, yes, there are plenty of us who have your back. If you get no response, you can @ mention me in here, just like in Twitter. I will do my best to answer as quickly as possible. I do have a job & family, so it isn't always within a few minutes, though! :smile:

Daniels Ilori
Daniels Ilori
538 Points

Oh yeah! I would of course... I am in Germany. I think its a difference of +1. Right now, it's 18:25 here.

Daniels Ilori
Daniels Ilori
538 Points

Alright...I promise not to delete anything. And thanks for the offer, I'll call you first once I get stuck again. :)

Java's a good topic for me, so please do! :smile:

i don't know where you are, so do consider the potential time difference. I'm in the UK so it is 23:26 here now. I should be going to bed but I'm watching TV and having a cheeky beer.