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 trialMatthew Earlywine
2,560 PointsI need to do something to make this open to the class. Not sure what I am doing wrong.
These GoKarts have a single rechargeable battery that have a display of bars to measure its energy level. Each battery has a maximum of 8 bars.
For this task, let's add a constant field to the class that stores the maximum number of energy bars. Make sure the fieldcannot be changed and is accessible from the class, not just the instance. Use the naming convention we learned.
public class GoKart { public final int MAX_BARS = 8; private String mColor;
public GoKart(String color) { mColor = color; }
public String getColor() { return mColor; } }
public class GoKart {
public final int MAX_BARS = 8;
private String mColor;
public GoKart(String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
}
3 Answers
Matthew Earlywine
2,560 PointsI figured it out all you have to do is: public static final int MAX_BARS = 8;
Matthew Earlywine
2,560 PointsI can't believe I didn't see that!!!! All I saw was MAX_NUMBER_OF_BARS and I was so confused why that would matter. Oh well, thanks for your help.
Kourosh Raeen
23,733 PointsNo worries :)
Kourosh Raeen
23,733 PointsMake it also static:
public static final int MAX_NUMBER_OF_BARS = 8;
Matthew Earlywine
2,560 PointsI still get the same error. I need to make it accessible from the class. I have rewatched the video for the quiz but I am not finding a way to do the naming convention.
Kourosh Raeen
23,733 PointsKourosh Raeen
23,733 PointsWell, that is exactly what I told you to do in my previous comment :)