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 Increment and Decrement

decrementing in a code

... may i be assisted in the third part of the question. "... in the drive method, decrement the battery's status that we maintain in the private field barCount."

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 void drive() {
    boolean wasDriven = false;
  {
  lapsDriven ++;
  wasDriven = true;
  }
  return wasDriven;

    {
      barCount = --;
    }
      }

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

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

2 Answers

Emmanuel C
Emmanuel C
10,636 Points

In the drive method, all they ask is to increment the lapsDriven property and decrement the barCount property.

public void drive(){
    lapsDriven++;
    barCount--;
}

Emmanual C you are correct, I am just adding this if someone else doesn't know what -- or ++ does. barCount--; is the same as barCount -= 1; which is the same as barCount = barCount - 1;

... thanks very much