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 Computed Properties

Surbhi Sinha
Surbhi Sinha
3,255 Points

problem with the code challenge

my code is not running and it is not accepting this double == sign. I think it's a simple if else statement, but not running

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

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

  public String getColor() {
    return color;
  }
  public boolean isBatteryEmpty(){
    if(barCount = = 0){
      return ();
    }

  }

  public void charge() {
    barCount = MAX_BARS;
  }
}

2 Answers

Susanne Wagner
Susanne Wagner
16,579 Points

The problem is, that barCount is null, because it had never been initialized. In the constructor you also have to initialize the barCount variable in order to ask if the Battery is empty or not.

public GoKart(String color, int barCount) { this.color = color; this.barCount = 1; }

In the method isBatteryEmpty you have to return true if barCount ==0, otherwise the method should return false. This way you can check battery status with this method.

Surbhi Sinha
Surbhi Sinha
3,255 Points

Thank you for your response ..it worked

Susanne Wagner
Susanne Wagner
16,579 Points

Try to use your own code from this post (not mine), but use the following isBatteryEmpty method.

The == shouldn't have a space inbewteen. The retunr statment doesn't need brackets

public boolean isBatteryEmpty(){
    if(barCount == 0){
      return true;
    }else{
      return false;
    }
  }
Surbhi Sinha
Surbhi Sinha
3,255 Points

Yeah have done that ..problem solved thanks