Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Harnessing the Power of Objects Method Signatures

James Barrett
James Barrett
13,253 Points

Completely 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

Hi 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
STAFF
Craig Dennis
Treehouse Teacher

Hi 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
James Barrett
13,253 Points

I did a little reading into what they are and after watching the following lesson I understood, thanks!