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 trialGreg King
4,073 PointsHaving trouble with method signatures
I can't figure out how to assign the method to this. I put drive(1) thinking that enough parameters were defined but apparently not. Can anyone help me understand how this is done? I feel this particular video lacked something to show me the translation between the 2 scenarios.
Thanks a bunch!
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;
drive(1);
}
public void charge() {
while (!isFullyCharged()) {
mBarsCount++;
}
}
public boolean isBatteryEmpty() {
return mBarsCount == 0;
}
public boolean isFullyCharged() {
return mBarsCount == MAX_BARS;
}
}
1 Answer
Ken Alger
Treehouse TeacherGreg;
I wrote a rather long winded explanation on this topic here. Take a look and if you are still stuck, please post back. This is an important topic and having a good understanding of it is important going forward.
Happy coding,
Ken
Greg King
4,073 PointsGreg King
4,073 PointsYes, indeed, Ken...thank you. This helps significantly but I think I need to read a little more on methods and classes before moving to the next step because I don't feel I totally grasp it. Thank you for the quick response. Also, should I be asking these questions differently?
Thanks, Greg
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherGreg;
I think you are right on track for the types of and way in which you are asking questions. It is great that you are doing so early on to make sure you have a solid foundation of knowledge.
Happy coding,
Ken