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 trialKenneth Kumentas
1,630 Pointsconfuse of load(MAX_PEZ)
what does this do?
Steve Hunter
57,712 PointsI'm on Skype - big.dog.consultants - or Twitter as OnlySteveH or on here. :-)
Kenneth Kumentas
1,630 Pointsokay thanks
2 Answers
Steve Hunter
57,712 PointsI carried on watching the videos so understand where you're coming from on this one! This is about overriding methods.
You originally have a method that sets the mPezCount
member variable to the value stored in the constant MAX_PEZ
. That makes sense, right?
Then, we're creating a new method that takes a number of items to add to the mPezCount
rather than just adding 12, or whatever. So, you have a new method that takes a parameter and add the value of that parameter to the number contained in mPezCount
. Make sense still? It just lets us add 1, or 2, or whatever rather than just MAX_PEZ
.
Having two methods called the same thing is fine as they both have different signatures, i.e. their first line is different - one takes a parameter, one does not.
Here, we can build some efficiency, though. You'll have heard of DRY coding (Don't Repeat Yourself) - well, here, we are repeating ourselves a little. Rather than having the first (non-parameter) function change the value of mPezCount
we can use the new function to do that for us. Inside of the old function, we call the new function, passing in MAX-PEZ
as the parameter. The new function then receives this and adds MAX_PEZ
to the value contained in mPezCount
.
That's just a little bit slicker and means that only one load()
method changes the value in mPezCount
.
OK with that?
Steve.
P.S. I still have no idea what a Pez Dispenser is or what Pez's are!?
Kenneth Kumentas
1,630 PointsA pez is a candy, and a pez dispenser is a candy dispenser. This program is a simulating on how a real pex dispenser works. such as being dispense, refill and also have a character name of the dispenser
Steve Hunter
57,712 PointsAh, I see - thank you! :-)
Craig Dennis
Treehouse TeacherHere ya go Steve Hunter PEZ
Steve Hunter
57,712 PointsThanks Craig Dennis ! :-)
Kenneth Kumentas
1,630 Pointshello craig i was just wondering if there will be a C course and also when will the java fx course comeout
Steve Hunter
57,712 PointsKenneth Kumentas
1,630 PointsThanks steve!, i did not notice that it just came out
Steve Hunter
57,712 PointsYep - just the other day. It's on my list to get on with! :-)
P.S. Did you get your head around the load(MAX_PEZ)
thing in this thread?
Kenneth Kumentas
1,630 Pointsyes i understand now. So now i know load(MAX_PEZ) on the first method means changing the parameter of the second method to MAX_PEZ so the numberOfPez + MAX_PEZ. thanks alot steve!
Steve Hunter
57,712 PointsCool - just checking it made sense. :-)
Kenneth Kumentas
1,630 PointsKenneth Kumentas
1,630 Pointssteve should i get your contact like on skype or should i just ask questions through treehouse? because you're really my go to guy when i'm confuse abt something