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 Harnessing the Power of Objects Changing State

William Smith
William Smith
3,840 Points

now create a method named charge that sets the new barCount field to the maximum amount of bars available for each GoKar

i keeps telling me to go back to task 1.

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

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

  public String getColor() {
    return mColor;
  } 

  public void charge(){
    mBarsCount = MAX_ENERGY_BARS;
  }  
}

1 Answer

Hi William,

The first task is Create a new private field named barCount. You've called yours mBarsCount. That's what's causing the issue, I think.

The tests are looking for a member variable called barCount to be set to the value of MAX_BARS, not MAX_ENERGY_BARS. So, you'll need to change the name of the constant back again too.

I hope that helps,

Steve.

macmondiaz
macmondiaz
1,415 Points

Hello Steve,

I'm having a problem on mine. It tells me to go to task 1 as well :

class GoKart {
  public static final int MAX_BARS = 8;
  private String color;


  public GoKart(String color) {
    this.color = color;
  }

  public String getColor() {
    return color;
  }

  private int barCount;

  public void String charge(){
    barCount = MAX_BARS;
  }
}

Hi there,

That's because your charge() method is returning void and String. It should just be void:

  public void String charge(){
    barCount = MAX_BARS;
  }

// should be:

  public void charge(){
    barCount = MAX_BARS;
  }

Steve.