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 trialIsheanesu Jindu
1,644 Pointsjava objects - method signatures
Bummer! Remember that you should call the existing drive method and pass in the default parameter of 1. Otherwise you would have to rewrite all that (omitted) code.
my code is
public void drive () {
mBarsCount -= 1;
}
2 Answers
Steve Hunter
57,712 PointsHi there,
The clue is in the error.
Because in the drive(int laps)
method there is a LOT of code that you don't see. That could be anything to do with type wear, fuel levels; lots of things we don't need to know about. So, you can't just do one thing, mBarsCount -= 1;
in the new drive
method.
You are asked to create an alternative drive
method that takes no parameters and just drives one lap.
So use the existing method inside the new one.
public void drive(){
drive(1);
}
That way, all the hidden code gets run and one lap gets completed.
Make sense?
Steve.
Isheanesu Jindu
1,644 Pointsman you are life saver, thank you !
Steve Hunter
57,712 PointsHey, no problem! :-)
Steve.
Daniel Marsh
4,533 PointsDaniel Marsh
4,533 PointsThank you, Steve Hunter i was very confused as well i had public void drive(){drive(laps)--;} not understanding that the code had so much hidden i understand much better now.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsNo problem, Daniel. Glad you got it fixed.
Steve.