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 trialDavid O'Mahoney
869 PointsOverloading Methods Challenge. Help needed.
Hi there, I cannot seem to answer this task correctly, I've spent an hour on it and I'm getting nowhere. Any help would be much appreciated. The preview console doesn't seem to be much help at all.
Thanks, Dave.
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 int drive( int lapsDriven) {
lapsDriven++;
barCount--;
}
}
4 Answers
Steven Parker
231,275 PointsYou've added the argument, but you still need to do the part of the instructions that say "Update the method body to handle the new parameter." That means instead of increasing/decreasing by one, you'll need to modify the internal variables by the amount in the parameter. Also:
- updating the body will be easier to do if the parameter name is different from the internal variables
- this method still does not return anything (is still "void")
David O'Mahoney
869 PointsThanks Steven, I have tried to answer the objective with the code you have suggested and it still doesn't seem to work. I think maybe the page is not checking the work correctly.
Steven Parker
231,275 PointsThat definitely should work for task 1. Are you on task 2?
David O'Mahoney
869 PointsYeah I am on task 1, it must be something wrong with the page, which is frustrating. Thanks again for your help.
Steven Parker
231,275 PointsTry restarting the browser and then perhaps your machine itself.
Mark Harrigan
7,686 PointsCan confirm the above worked for me, thank you Steven!
David O'Mahoney
869 PointsDavid O'Mahoney
869 PointsHi Steven, thank you for your help, unfortunately after a couple more hours I still can't get the correct answer, I just really don't understand it, think I'm going to have to give up on this track, which is frustrating as I was enjoying it!
I'm sorry for what was probably a very simple question but I'm completely new to any sort of coding and I'm finding very difficult.
Thanks again for you help.
Steven Parker
231,275 PointsSteven Parker
231,275 PointsIn case it helps, here's an example of what it might look like with my hints applied: