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

Ibrahim Tahir
463 PointsHow to name a void method please help in Java this is the method =. public void fill () { barCount = MAX_PEZ }
Please help this is from getting started with Java.
3 Answers

Steve Hunter
57,712 PointsHi,
So, the first task is Create a new private
field named barCount
that will track how many bars of energy our GoKart battery currently has. You add that at the top of the class. This is going to hold a number so it is of datatype int
- the question tells us it is private
.
That looks like:
private int barCount;
The next task is Now create a method named charge
that sets the new barCount
field to the maximum amount of bars available for each GoKart. So, you don't want a method called fill()
but one called charge()
. Let's assume it is public
and returns nothing - you've correctly identified that would need public void
at the beginning. The method is called charge
and takes no parameters. Inside the method, set the variable you created above, called barCount
, to the constant value held in the class already. That is called MAX_BARS
; nothing to do with pez dispensers!!
So, you need to change your method name to charge()
and inside the method assign MAX_BARS
into barCount
. Add the semicolon and you're done!
That looks like:
public void charge(){
barCount = MAX_BARS;
}
Steve.

Steve Hunter
57,712 PointsHi there,
Difficult to say without a link to the challenge but one thing that's wrong with your code is a missing semi-colon at the end of the line.
You've pasted the method onto one line in the title, but I think it should look something like this:
public void fill(){
barCount = MAX_PEZ;
}
You've missed the semicolon at the end of the line inside the method.
Steve.

Ibrahim Tahir
463 Points
Ibrahim Tahir
463 PointsPLZ HELP

Ibrahim Tahir
463 PointsThanks for giving some time to give me this answer.
Regards Ibrahim

Steve Hunter
57,712 PointsNo problem - I hope you got going again!
Good luck.
Steve.

Iheke Iheke-agu
Full Stack JavaScript Techdegree Student 2,307 PointsFor some reason I had to put public void charge(){ barCount = MAX_BARS; }
underneath my constructor. it kept saying oops looks like step 1 is no longer passing