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 triallee lewis
Courses Plus Student 5,796 PointsI dont understand what it means by "passing a 1"... and how I should write it in code..
I'm also not sure what drive method they are refering to when they say "new drive method".... I have two drive methods... and i dont understand what is supposed to be different on the the drive method that i thought was supposed to be just a repeat of the original drive method
class GoKart {
public static final int MAX_BARS = 8;
private String color;
private int barCount;
private int lapsDriven;
public GoKart(String color) {
this.color = color;
}
public String getColor() {
return color;
}
public void charge() {
barCount = MAX_BARS;
}
public boolean isBatteryEmpty() {
return barCount == 0;
}
public boolean isFullyCharged() {
return MAX_BARS == barCount;
}
public void drive(int shouldDrive) {
lapsDriven++;
barCount--;
lapsDriven += shouldDrive;
barCount -= shouldDrive;
}
public void drive() {
lapsDriven++;
barCount--;
shouldDrive += 1;
}
}
3 Answers
Steven Parker
231,072 PointsIn task 1 you were meant to change the drive method, so you would have still had only one method with that name, but now it takes an argument. Also, the increment/decrement inside it should be done only once each, using the argument.
In task 2, you will create a second drive method, this time that takes no arguments, but inside all it does is to call the other (modified) one using a 1 as the argument (that's "passing a 1").
lee lewis
Courses Plus Student 5,796 Pointsno offense,
i appreciate people trying to answer but that answer told me nothing.. it just repeated what the question was saying.
can someone actually explain this to me with some 'code' because ive been stuck on this for two days now and im getting nowhere.
what does "passing a 1 mean?"... what is being 'passed'.... from where and to where is it being passed? can someone write a piece of code to explain it please!!!
Steven Parker
231,072 PointsOK, here's the code calling the modified method and "passing a 1":
drive(1);
When you call a method, you put parentheses after the name, and inside the parentheses, you put the argument(s) that you are passing. The value 1 is being passed to the shouldDrive parameter that you added to the modified method.
lee lewis
Courses Plus Student 5,796 Pointsthankyou Steven.. i actually got just after i sent last message but i appreciate your help.. sorry if my last message sounded a bit snarky... ive been stuck on that problem for ages and I think I was starting to get my knickers in a twist over it lol.
again very much appreciate the help
Steven Parker
231,072 PointsI know frustrations can take a toll but good to hear you've conquered the issue now.
Happy coding!