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 trial

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,887 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!