Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Harnessing the Power of Objects Overload Methods

Dafei Lu
Dafei Lu
1,221 Points

Used "+=" increment but still not working...

Hi guys, I understand that we are supposed to increment the labsDriven to the new parameter. Seems having trouble to implement that... Any ideas?

GoKart.java
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 labsAmount) {
    labsDriven += labsAmount;
    barCount--;
  }
}

2 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,862 Points

Hi Dafei,

You have a couple of issues in your method. The first is a simple typo: you are using labs when you should be using laps.

The second is that you haven't made the corresponding change to barCount that you made to lapsDriven. Recall that the original file had the line:

lapsDriven++;

which would increment lapsDriven by one every time the method was called. The modification that you made (once the typo is fixed) increases lapsDriven by lapsAmount and saves that increased value back into the lapsDriven variable each time the method is called.

You need to make a similar change to barCount. In the original version of the program, every time the method was called, barCount would be decremented by 1. You now want barCount to be reduced by lapsAmount and have that new, lower, value to be written back to barCount.

Hope that helps

Cheers

Alex

Dafei Lu
Dafei Lu
1,221 Points

Hi Alex, Thank you so much for your time and detailed explanation! I fixed these two bugs and the challenge was resolved. Thank you again!