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

Michelle Bramlett
Michelle Bramlett
1,253 Points

Java Helper Method Challenge Task 2 receiving 1 error Ln 26 "Cannot find symbol" Stuck! Please help

Been stuck on this challenge too long:/ Researched other answers on forum and still not passing Insight, please!

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 void charge() {
   if (isBatteryEmpty()) {
     mBarsCount ++;
   }
 }

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

  public boolean isFullyCharged() {
    return mBarsCount == MAX_BARS;
  if(!isBatteryEmpty) {
    return true;
  } 

  }

}
Simon Coates
Simon Coates
28,694 Points

The following still crashes, but shows the updated code.

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 void charge() {
   if (isBatteryEmpty()) {
     mBarsCount ++;
   }
 }

  //task 1:
  public boolean isBatteryEmpty() {
    return mBarsCount == 0;
  }
  //task2
  public boolean isFullyCharged() {
    return mBarsCount == MAX_BARS;
    //the following will never fire.
  /*
    if(!isBatteryEmpty) {//should be if(!isBatteryEmpty())
    return true;
  }*/
  }
}

I get the message "Bummer! Your method should return true when mBarsCount is full.". However, it goes away when I copy in:

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 void charge() {
    mBarsCount = MAX_BARS;
  }

  //task 1:
  public boolean isBatteryEmpty() {
    return mBarsCount == 0;
  }
  //task2
  public boolean isFullyCharged() {
    return mBarsCount == MAX_BARS;
    //the following will never fire.
  /*
    if(!isBatteryEmpty) {//should be if(!isBatteryEmpty())
    return true;
  }*/
  }
}

which has the original charge method. SO YOU DID CHANGE SOMETHING IN ADDITION TO THE TASK AND IT MAY HAVE BEEN GIVING YOU FAULTY ERROR MESSAGES.

1 Answer

Simon Coates
Simon Coates
28,694 Points

got it to work with:

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 void charge() {
    mBarsCount = MAX_BARS;
  }
  public boolean isBatteryEmpty(){
     return mBarsCount == 0; 
  }
  public boolean isFullyCharged(){
     return mBarsCount == MAX_BARS; 
  }
}
Michelle Bramlett
Michelle Bramlett
1,253 Points

Thanks Simon! My code was getting way to complicated as I was trying to get help. I can follow the simplicity of yours above( and it worked;)