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 (Retired) Harnessing the Power of Objects Helper Methods

Eric Greer
Eric Greer
4,997 Points

Returning Boolean but not working?

I am returning the boolean result of the mBarsCount == 0 evaluator but the test keeps asking me to return a Boolean...

GoKart.java
public class GoKart {
  public static final int MAX_BARS = 8;
  private String mColor;
  private int mBarsCount;

  public GoKart(String color) {
    mColor = color;
    mBarsCount = 0;
  }

  public String getColor() {
    return mColor;
  }
  public Boolean isBatteryEmpty(){
    return mBarsCount == 0;
  } 
  public void charge() {
    mBarsCount = MAX_BARS;
  }
}

2 Answers

I think that the problem may be one of case, with Boolean and boolean being different.

Also, sorry about posting this twice. I'm quite new to the forums here, and didn't see the answer section hidden at the bottom of the page.

Eric Greer
Eric Greer
4,997 Points

You were right! The uppercase Boolean is valid java but apparently not in the team tree house editor (for at least this challenge). When i lowercased the boolean on the method, it worked perfectly. Thanks!

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Eric;

In Java, Boolean returns true or false, not 0 or 1, which are of type int.

Ken

Eric Greer
Eric Greer
4,997 Points

mBarscount is followed by two equals signs, making it an evaluator. The entire section mBarsCount == 0 should be resolved into a Boolean true or false then returned in the isBatteryEmpty method.

Ken Alger
Ken Alger
Treehouse Teacher

Doh! You're correct. Blurring eyes tonight, sorry.

Eric Greer
Eric Greer
4,997 Points

I appreciate you taking the time to read my question!