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 Java Objects (Retired) Harnessing the Power of Objects Method Signatures

I am stuck in that challenge tried but cannot resolve it please any help will really appreciated

I am adding the drive method with no argument but its giving me compiler error. no clue what to do ?

6 Answers

A little more info on what you tried might be helpful, but I'll do my best to cover what you could have done. First and foremost, check for syntax errors. Make sure that your drive method still has all the necessary components. Just because it takes no arguments doesn't mean that it doesn't need access control (public) or a specified return type (void). Make sure that you define it as you would any other method. Don't do anything like put it inside the already defined drive method. And, the last thing I can think of is making sure that the method does the correct thing, though a mistake here wouldn't necessarily cause a compiler error. This method is meant to subtract 1 from mBarsCount, something that you have already written more abstractly in your drive method that takes an int.

If I didn't answer your question, or you have more questions, let me know. Maybe include your code in your question next time, so that it's easier to see where you're struggling.

The content of your method is what you want it to do, just as with any other method. You want to subtract 1 from mBarsCount. That's all. You can do that by writing

public void drive(){
    mBarsCount--;
}

or by writing

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

since you have already given your 1-argument drive method the desired functionality.

Ah, well they're just saying there that they want you to specifically do the second version of the method, i. e. 'drive(1);'.

I did public void drive () {

What should I write over here ???

}

I tried the same code and it gives me this error:

Remember you should call this drive existing method and pass in the default parameter of 1. Otherwise you have to rewrite all that omitted code.

surprisingly it works this time thank you so much for your help.