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 trialJames Barrett
13,253 PointsCompletely lost with understanding the load methods!
Hi there,
I am completely lost on this exercise. I'm not sure if the termnology is confusing me in this exercise but here is what I think is happening in simple terms:
If the load() method is called in example.java without any arguments, the pez dispenser will be loaded to 12. However if it is supplied with an argument (i.e. 4), this will be added to the amount of pez currently in there.
However Craig says that we have introduced a big error to the program and I am struggling to find where the big error is.
Am I on the right track? Also where is this 'error' that has been introudced?
Thanks, James.
2 Answers
Benjamin Singh
15,248 PointsHi James,
the maximum amount of candies the Pez Dispenser can take is 12. We defined it with the constant MAX_PEZ = 12. But in the current state of the program it's possible to load an infinity amount of candies into the Pez Dispenser which shouldn't be allowed.
Just try it with dispenser.load(100). The Pez Dispenser will have +100 candies.
I think this is the error.
Craig Dennis
Treehouse TeacherHi James Barrett !
It might help if I shared some details about a PEZ Dispenser in case you aren't familiar with it.
We are overloading what it can handle, so we need to catch it.
Hope it helps!
James Barrett
13,253 PointsI did a little reading into what they are and after watching the following lesson I understood, thanks!