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 trialkumbirai mangwanda
1,628 PointsCreate a new method named drive that accepts no arguments.
It should call the newer drive method passing in a 1 for the default.
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 (int laps) {
lapsDriven+=8;
barCount-=0;
}
public int drive {
lapsDrive+=8;
barCount-=0;
}
}
1 Answer
Zachary Kaufman
1,463 PointsYour drive method needs to have (), as all methods do.
Also drive shouldn't return an integer, it is just like the first drive method except it takes no arguments, so...
public void drive() {}
and it also says the new drive method should CALL the old drive method. This does not mean copy and paste the old drive methods code inside the new one, just call the old drive by doing...
public void drive() {
drive(1);
}
Java can tell which method you are calling based on the arguments you passed. The new drive method just allows the user to have a default of one lap. Your final answer should be the code above. I hope this helps.