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

Okay, so let's use our new isFullyCharged helper method to change our implementation details of the charge method. Let's

i dont know where am going wrong.My u help please.

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() {
  while (! isFullyCharged() ) {
    mBarsCount++;
  }
}
  public boolean isBatteryEmpty() {
    return mBarsCount == 0;
  }

  public boolean isFullyCharged() {
    while (!isBatteryEmpty()) {
    mBarsCount ++;
   isFullyCharged = false;   
  }
    return mBarsCount == MAX_ENERGY_BARS;
  }


}

Hi Edwin,

The backticks work OK on their own but are much better if you stipulate the language after the first three.

Make sure you're not using back slashes or single quotes too. I'll reformat your comment now to demonstrate, go in and edit it after I have done that to see the markup displayed.

Steve.

[edit] Craig beat me to it!!

5 Answers

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

Change isFullyCharged back to how it was originally, from your previous challenge.

Hi,

Have a look through this post to see if that helps you out.

Cheers,

Steve.

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

I think you should leave the isFullyCharged method alone, and just use charge

Edwin Amaya
PLUS
Edwin Amaya
Courses Plus Student 809 Points

i think you are setting battery as empty instead of checking if its empty so everytime the isFullyCharged methods checks to see if it its empty it is being actually set to empty and thus will never be full

 public boolean isBatteryEmpty() {

    return mBarsCount == 0; // 

  }

ps to the admins: i dont know how to enter "code" i used the back ticks like the markdown sheet said but it doesnt format the code

Craig Dennis
Craig Dennis
Treehouse Teacher

Hey Edwin,

I fixed your answer and I did it by adding 3 back ticks on a line followed by the word java (If you edit it you can see it) and then followed it with 3 backticks.

Thanks!

Edwin Amaya
PLUS
Edwin Amaya
Courses Plus Student 809 Points

ahh I see! said the blind man as he headed out to sea! thanks guys.