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

I don't understand the Code Challenge "Method Signatures".

Challenge Task 1 of 1


I have added a method drive that defines a parameter laps. These high-powered GoKarts use 1 energy bar off their battery per lap.

Using method signatures, add a new default method called drive that

performs just 1 lap and takes no arguments


Important: The code you write in each task should be added to the code written in the previous task.

7 Answers

Can you explain what you don't understand about it?

I don't understand what code I should put in.

It seems that you just need to create a new method called drive to simulate the goKart performing one lap (i.e. taking away 1 from the battery). The method doesn't require anything to be put in and won't need to return any value. Give it a go, and if you're stuck - post what you tried here on the forum and we can help you further.

I cannot figure out how to limit the laps to one.

You dont need to limit the laps to 1. All the method needs to do is -1 from the battery.

ERROR FOUND:

public void drive() { drive(1); }

Not sure what the variable names were now, but didn't you have:

public void drive(){ mEnergyBars -= 1; }

or something? That seems like it should work.