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 Methods and Constants

Gokart charging. get the error message " Bummer! Please make the field mBatteryCount final so that it cannot be change

Gokart charging. get the error message " Bummer! Please make the field mBatteryCount final so that it cannot be changed...

but if i do that i can not fill the battery up later... im lost

GoKart.java
public class GoKart {

  private String mColor;
  public static final int MAX_BATTERY = 8;
  public int mBatteryCount;

  public GoKart(String color) {
    mColor = color;
    mBatteryCount = 0;
  }
  public void load() {
    mBatteryCount = MAX_BATTERY;
}
  public String getColor() {
    return mColor;
  } 
}

2 Answers

I'm not sure where mBatteryCount is found in the challenge. Challenge 2 says to name your field mBarsCount. This might be the source of your problem; because the system thinks mBatteryCount is from challenge 1.

My final answer on this one was:

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

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

  public String getColor() {
    return mColor;
  }

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

it's mBarsCount only a different name... since a specifik name wasn't in the asignment it should not make a difference but i will try

EDIT: i was still on the first part. i was just a little ahead of myself

it did

Corey Johnson
PLUS
Corey Johnson
Courses Plus Student 10,192 Points

I just tested this challenge and did not have any issues. You code is technically correct but it is not exactly as requested in the challenge notes.

The only difference in the code i used to successfully complete the challenge is:

  1. make the mBatteryCount variable private
  2. the method that reloads the battery should be called "charge" instead of load.

Hope this helps.

thx for the reply.. however this did NOT solve the problem. as it was like that to start. i changed to charge. didn't make a difference. it still justy asks me to first make the mBatteryCount public then it wants me to make it final. and if i do that i get an error that i cant change a final... do frustrating