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

These GoKarts have a single rechargeable battery that have a display of bars to measure its energy level. Each battery h

am stuck on how to answer the whole question please help me.

GoKart.java
public class GoKart {
  private String mColor;

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

  public String getColor() {
    return mColor;
  } 
}

4 Answers

Look at this code for your example to follow:

public class PezDispenser {
  public static final int MAX_PEZ = 12;
  private String mCharacterName;
  private int mPezCount;

  public PezDispenser(String characterName) {
    mCharacterName = characterName;
    mPezCount = 0;
  }

  public void load() {
    mPezCount = MAX_PEZ; 
  }

  public String getCharacterName() {
    return mCharacterName;
  }
}
  • Instead of MAX_PEZ, you are creating MAX_BARS
  • Instead of mPezCount, you are creating mBarsCount
  • Instead of a load method, you are creating a charge method

Thanks that really helped.

Vedang Patel
Vedang Patel
7,114 Points

look at this code cause its the answer: public class GoKart { public static final int MAX_BARS = 8; private String mColor; private int mBarsCount;

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

public String getColor() { return mColor; } }

Allan Clark
Allan Clark
10,810 Points

IIRC this exercise will walk you through inserting a member variable and a couple methods.

You need a member variable for the battery, all it has to do is keep up with the number of bars so an int will do.

For the methods you should just need to write the logic for when a bar needs to be subtracted.

That is as best I can do with such a general question. Hit me up with more specifics if you need.

THANK YOU.Let me try work with what you have given me.