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

Alwayne Harrison
Alwayne Harrison
2,069 Points

I'm stuck, what should I do to successfully modify my drive method the way the challenge has requested?

I have tried reading the forum but still no luck. Please Help. I will attach my code.

GoKart.java
class GoKart {
  public static final int MAX_BARS = 8;
  private String color;
  private int barsCount;
  private int lapsDriven;
  private int laps;

  public GoKart(String color) {
    this.color = color;
  }

  public String getColor() {
    return color;
  }
  public void charge() {
    barsCount = MAX_BARS;
  }

  public boolean isBatteryEmpty() {
    return barsCount == 0;
  }

  public boolean isFullyCharged() {
    return MAX_BARS == barsCount;
  }

  public void drive (int laps); {
    lapsDriven+=;
    barsCount-=;
  } 
}

2 Answers

Robert Stefanic
Robert Stefanic
35,170 Points

Hi,

You're mixing up your shorthands here in this final method:

  public void drive (int laps); {
    lapsDriven+=;
    barsCount-=;
  } 

If you use "+=" or "-=", then you need to follow it up with something. So for example, if you want to subtract one from barsCount, then you'll need to write barsCount -= 1.

The other short hand is "++" and "--". If you only wanted to subtract one from barsCount, you'd write it like this:

barsCount--;

So if you want to use "-=" or "+=", then you need an amount after it in order to either add or subtract from the variable. on the left. The short hand "++" adds one to the variable while "--" subtracts one from that variable.

Alwayne Harrison
Alwayne Harrison
2,069 Points

Thank you so much, with your help I finally managed to pass the challenge. Cheers

Michael Davis
PLUS
Michael Davis
Courses Plus Student 12,508 Points

Your Code:

public void drive (int laps); {
  lapsDriven+=;
  barsCount-=;
}

You have the argument laps declared, but never used. Also, you have both lapsDriven and barsCount adding and subtracting, but the statement is incomplete.

If we want to add the given number of laps in the property laps, then use

+= laps
-= laps
Alwayne Harrison
Alwayne Harrison
2,069 Points

Thank you. Your reply cleared up the misunderstanding perfectly. Cheers