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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![shiny peanut](https://uploads.teamtreehouse.com/production/profile-photos/10239362/micro_20220320_085358.jpg)
shiny peanut
5,113 PointsOverloading methods/confused about what the second task is asking for
The second task on this code challenge is really confusing to me. It would seem to imply that I deleted the first drive method, but the instructions pretty much tell you not to delete code from previous completed tasks.
I don't get what it means when it wants the newest drive method to call the one from before with a default int of 1. Can somebody show me how this is supposed to be done and explain how it works? I feel like the Java Objects course is moving much faster than the Java Basics course did and I'm not sure how well I'm understanding each things before he moves on, even in the same video,
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() {
lapsDriven++;
barCount--;
}
public void drive(int lapAmount){
lapsDriven += lapAmount;
lapAmount -= barCount;
}
public void drive(int 1){
drive(MAX_BARS);
}
}
3 Answers
![Tomasz Obidowski](https://secure.gravatar.com/avatar/0a60e6971a68ad5ba779dc6d72322c03?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Tomasz Obidowski
984 PointsI had this same problem. Thanks.
![Clayton Perszyk](https://secure.gravatar.com/avatar/91570a217e3dbbeb3a4bb32bd92c70e8?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Clayton Perszyk
Treehouse Moderator 48,838 PointsThe first question is asking that you modify the existing drive method (i.e. you're not adding overloading the method). The second task is asking that you use the modified method, which now takes an int, in a new drive method that takes no arguments.
Your code:
public void drive() { // remove this
lapsDriven++;
barCount--;
}
public void drive(int lapAmount){ // keep this
lapsDriven += lapAmount;
lapAmount -= barCount;
}
public void drive(int 1){ // this should call drive with argument 1; it shouldn't take any arguments
drive(MAX_BARS);
}
![shiny peanut](https://uploads.teamtreehouse.com/production/profile-photos/10239362/micro_20220320_085358.jpg)
shiny peanut
5,113 PointsI understand the first part, but I still have no idea what the solution to the second part would be. I don't know what that would look like in code. What does argument 1 mean?
![Clayton Perszyk](https://secure.gravatar.com/avatar/91570a217e3dbbeb3a4bb32bd92c70e8?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Clayton Perszyk
Treehouse Moderator 48,838 PointsInstead of passing MAX_BARS to drive , you pass 1.
public void drive() {
drive(1);
}