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 trialMUZ140564 Kudakwashe Jena
4,895 PointsThese 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.
public class GoKart {
private String mColor;
public GoKart(String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
}
4 Answers
Jess Sanders
12,086 PointsLook 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
Vedang Patel
7,114 Pointslook 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
10,810 PointsIIRC 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.
MUZ140564 Kudakwashe Jena
4,895 PointsTHANK YOU.Let me try work with what you have given me.
MUZ140564 Kudakwashe Jena
4,895 PointsMUZ140564 Kudakwashe Jena
4,895 PointsThanks that really helped.