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

David Geoffry
David Geoffry
444 Points

Error of my program

Make sure your isFullyCharged method is checking for equality between barCount and MAX_BARS Can not find my mistake if one you guys can help that would be great!

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

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

  public String getColor() {
    return color;
  }

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

 public boolean isFullyCharged() {
 while(!isFullyCharged()) {
 mBarsCount++;
 }
 }


}

2 Answers

Richard Lambert
PLUS
Richard Lambert
Courses Plus Student 7,180 Points

Hello mate,

You've rightfully declared the isFullyCharged() method as having a return type of boolean, however it doesn't actually return anything as it's written. The boolean value to be returned is the result of evaluating is barCount equal to MAX_BARS. Can you picture what that looks like in code?

public boolean isFullyCharged() {
    return //???
}

Hope this helps

Anders Björkland
Anders Björkland
7,481 Points

Hi Kelton! If you look in your isFullyCharged(), you see that the method doesn't return any boolean. Since you declared that it should return a boolean and it doesn't - your code won't compile. This is the first step.

Second; like you did in the method isBatteryEmpty, do the same in isFullyCharged(), but have barCount compared to MAXBARS and return the resulting boolean.

Third; look at your variable names. As it is right now, you have three different names for what I believe is supposed to be the same (maybe you have been changing in your code, but forgot to change in other places in your code?). The integer barcount, mBarcount, and mBarsCount should probably have the same name. Anyways, mBarcount and mBarsCount are not declared, so they will also prohibit the code from compiling.

Your implementation of isFullyCharged() method seem to actually be a refueling-method that is using a isFullyCharged-method. Rename that method if that is the case, and start building the implementation again for isFullyCharged and make it as sleek looking as your awesome isBatteryEmpty-method.

Good luck, and have fun =)