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 trialkai Detmers
614 PointsWhat is the method I have to add to the code? I can't get it to work.
Thank you so much for your help!
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;2
}
public void drive(int laps) {
// Other driving code omitted for clarity purposes
mBarsCount -= laps;
}
public void drive() {
// Other driving code omitted for clarity purposes
drive();
}
public void charge() {
while (!isFullyCharged()) {
mBarsCount++;
}
}
public boolean isBatteryEmpty() {
return mBarsCount == 0;
}
public boolean isFullyCharged() {
return mBarsCount == MAX_BARS;
}
}
1 Answer
Steve Hunter
57,712 PointsHiya,
There's an existing method called drive
that takes the number of laps the kart should drive.
In this challenge, you want to override that with a new method signature that takes no parameters.
The question asks you to create a method signature for drive
that takes no parameters and makes the kart do one lap. You can ose the existing method within this new one. The new method looks something like this:
public void drive() { // new method with no parameters
drive(1); // calls the existing method for just one lap
}
I hope that makes sense!
Steve.
Bryan Tidwell
3,473 PointsBryan Tidwell
3,473 PointsI get why that's the answer, but I'm just really struggling to understand the logic behind it. How does this tell the program that it's only doing one lap? We haven't defined that "drive" is even associated with "laps", have we??
Or is it the previous method that does that for us?? So confused...