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 Incrementing

I have an error that says there is several errors that are on lines of code that don't exist. Please help.

The console says: symbol: method isBatteryEmpty() location: variable kart of type GoKart JavaTester.java:81: error: cannot find symbol if (!kart.isBatteryEmpty() || kart.isFullyCharged()) { ^ symbol: method isFullyCharged() location: variable kart of type GoKart JavaTester.java:85: error: cannot find symbol kart.charge(); ^ symbol: method charge() location: variable kart of type GoKart JavaTester.java:86: error: cannot find symbol if (!kart.isFullyCharged()) {
However, the code it features doesn't exist, and the lines they are on don't exist either.

GoKart.java
public class GoKart {
  public static final int MAX_ENERGY_BARS = 8;
  private String mColor;
    private int mBarsCount;
while (goKart.charge()) {
      }
  public GoKart(String color) {
    mColor = color;
    mBarsCount = 0;
  }

  public String getColor() {
    return mColor;
  }

  public void charge() {
    mBarsCount = MAX_ENERGY_BARS;
  }

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

  public boolean isFullyCharged() {
    return mBarsCount == MAX_ENERGY_BARS;
  }

}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I suspect that the reason you are seeing this is not an error from your code, but rather errors generated from the piece of code that's testing your code.

However, I can give you some hints here:

  • The while loop you are intended to write will go in the charge method. Not at the top of your code.
  • System.load() is not needed for this challenge. This is a method used to load in a Java library.

Hope this helps! :sparkles:

O.K.. How would fix the first one?

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I'm sorry that the hints weren't quite enough. Here's the while loop it wants shown in the correct method.

 public void charge() {
    while(!isFullyCharged()) {
      mBarsCount++;
    }
  }

This method says while the battery is not fully charged, increment the energy bars by one. Hope this helps! :sparkles:

Solved. Thanks.