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 trialSudhanshu Bhatia
274 PointsGreat! Now let's write a simple drive method. It should be public and not return anything. We'll start out basic, callin
it showing that previous task is not completed but previous i have done successfully..
class GoKart {
public static final int MAX_BARS = 8;
private String color;
private int barCount;
private int lapsDriven;
public void drive(){
lapsDriven += 1;
}
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;
}
}
2 Answers
andren
28,558 PointsThis challenge is looking for a specific incrementing technique to be used which is this:
public void drive(){
lapsDriven++;
}
Adding ++
after a variable name will increase it by one. That is what the task refers to when it mentions "the incrementing shorthand" which it requires you to use.
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi there,
If task 1 isn't showing as completed either there was a minor error in the previous task or something in the corresponding task has caused it to fail.
What you've written is technically correct but there's another way of incrementing the value that the challenge wants you to do.
You need to use the shorthand post increment operator
lapsDriven++ to pass this task.
Omid Halavi
1,416 Pointsclass GoKart {
public static final int MAX_BARS = 8;
private String color;
private int barCount;
private int lapsDriven;
public void drive() {
lapsDriven++;
}
This is how i wrote the code but it still tells me Oops! It looks like Task 1 is no longer passing. What am i doing wrong?