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

im lost

where am i getting it wrong?

GoKart.java
public class GoKart {
  public static final int MAX_ENERGY_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_ENERGY_BARS;
  }

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

  public boolean isFullyCharged() {
    return mBarsCount == MAX_ENERGY_BARS;
  }
  public void charge() {
    while(!isFullyCharged()) {
    mBarsCount ++;
    }
  }

}
Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey ho,

here is the code that should work fine !

public class GoKart {
  public static final int MAX_ENERGY_BARS = 8;
  private String mColor;
  private int mBarsCount;

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

  public String getColor() {
    return mColor;
  }

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

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

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

Grigorij

Grigorij Schleifer u are the best, thank u thank u

3 Answers

There's only one problem, charge method is already define. change it's implementation. don't make another charge method. :)

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Carlson,

you are soooo close ...

In this challenge you donΒ΄t need to change the isFullyCharge method at all because this method is already good to go. Use it inside the charge method to proof the charge state of your GoKart. And you have the working code already:) but in the wrong method.

take this:

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

and paste it intoo the existing charge method. And it should be great :)

So Inside your charge method :

public void charge() {
    while (!isFullyCharged()) { 
// while not fully charged please increment the mBarsCount
//
      mBarsCount++;
    }
  }

You can delete "mBarsCount = MAX_ENERGY_BARS" inside charge() because you set the mBarsCount if your GoKart is not FullyCharged :)

Let us know if you need more help and donΒ΄t give up

Grigorij

Hi Grigorij, the link u sent me cannot open i dont knw why it keeps saying page not found

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

I know, I am writing a more complex answer. If you want to use the link, please delete the last 4 characters

it still asked me to add a while statement please help im lost!

Kevin Faust
Kevin Faust
15,353 Points

What Grigorij wrote worked for me. Just refresh your page, and change the default charge method to what he wrote.

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Carlson,

glad to help you :)

Mark it as best answer, so other Java-Warriors can use it for their research

Grigorij