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 trialnaiara gonzalez
16,778 PointsI dont know what is wrong with this code,can anyone help me,please?thanks anyway
Question: 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 field cannot be changed and is accessible from the class, not just the instance. Use the naming convention we learned.
public class GoKart { public static final int MAX_B = 8; public final int mBattery; private String mColor;
public GoKart(String color) { mColor = color; }
public String getColor() { return mColor; }
public void battery() { mBattery = MAX_B; }
} my code:
public class GoKart {
public static final int MAX_B = 8;
public final int mBattery;
private String mColor;
public GoKart(String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
public void battery() {
mBattery = MAX_B;
}
}
public class GoKart {
public static final int MAX_B = 8;
public final int mBattery;
private String mColor;
public GoKart(String color) {
mColor = color;
}
public String getColor() {
return mColor;
}
public void battery() {
final mBattery = MAX_B;
}
}
6 Answers
Jess Sanders
12,086 PointsIf you want to simply start over, you may have a better understanding of what is happening in this challenge, and how it relates to the lesson. 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
ISAIAH S
1,409 Pointspublic String getColor {
should be:
public void getColor {
i.e. "String" should be "void".
Hope it helps,
ISAIAH S
Craig Dennis
Treehouse TeachergetColor
should return a String
like it says.
naiara gonzalez
16,778 PointsI changed String for void and it didnt work....
Craig Dennis
Treehouse TeacherNot sure where the finals are coming from... Try removing them.
Are you getting compilation errors? What are they?
naiara gonzalez
16,778 PointsThis is my compiler error: /GoKart.java:14: error: expected final mBattery = MAX_B; ^ ./GoKart.java:11: error: cannot return a value from method whose result type is void return mColor; ^ ./GoKart.java:14: error: cannot find symbol final mBattery = MAX_B; ^ symbol: class mBattery location: class GoKart 3 errors
MUZ140564 Kudakwashe Jena
4,895 Pointson the character name what do i put.?
Jess Sanders
12,086 PointsYou aren't making any methods that use character name. You only need to follow the example of the load method.
Damien Dale
Courses Plus Student 2,422 Pointspublic class GoKart {
public int mBars = 0 ;
private String mColor;
public static final int M_COUNT = 8;
public GoKart(String color) {
mColor = color;
}
public void mBarCount(){
mBars = M_COUNT;
}
public String getColor() {
return mColor;
}
}
...