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
Theodor Fahami
1,034 PointsHelp with treehouse challenge
This is my code:
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; }
public void drive(int laps) { // Other driving code omitted for clarity purposes mBarsCount -= laps; }
public void charge() { while (!isFullyCharged()) { mBarsCount++; } }
public boolean isBatteryEmpty() { return mBarsCount == 0; }
public boolean isFullyCharged() { return mBarsCount == MAX_BARS; }
}
This is my challange: I have added a method drive that defines a parameter laps. These high-powered GoKarts use 1 energy bar off their battery each lap. Using method signatures, add a new method called drive that performs just 1 lap and takes no arguments.
I do not know how to do that, i tried adding this:
public void drive() {
drive(laps = 1);
}
but that does not work.
Can I get help with understanding what to do?
1 Answer
andren
28,558 PointsThe problem is how you try to pass the the laps argument to the method, you don't pass arguments by specifying the name and then the value, you simply type the value and that's all, the code should look like this:
public void drive()
{
drive(1);
}
Since 1 is the first argument you pass it will automatically be assigned to the first parameter of the method.
If there is still something that confuses you then feel free to ask me follow up questions, I'll do my best to clear things up for you.
Theodor Fahami
1,034 PointsTheodor Fahami
1,034 Pointsthanks for making it clear!