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'm stuck....

I am confused, I understand the purpose of the videos to explain the concepts, but then I got attempt a challenge, but I find myself 9/10 times struggling to begin with because the content isn't the same. That throws me off.

When I try to just grasp the main concepts and apply those to the coding example. It works obviously when I understand it, but it seems that when I implement the same code it doesn't seem to work the same. For example in this current challenge I was using the similar code as provided in the video, tweaking it of course for the variable names.

However, I find I have tons of errors. I am just baffled, and need a little help please.

I understand the concepts, I guess I am having a rough time understanding how to write it all out, and where to put it.

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;
  }


}

1 Answer

Dan Johnson
Dan Johnson
40,533 Points

This challenge can be difficult to follow since the modifications to the charge method won't actually change any behavior. It's more to illustrate the use of the ++ operator and to put to use the isFullyCharged method.

So in the charge method you'll be restructuring it in the following way:

public void charge() {
   // While the GoKart isn't fully charged:
   //      increment mBarsCount    
}