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

Java Java Objects (Retired) Harnessing the Power of Objects Incrementing and Decrementing

Kim Gee
Kim Gee
3,841 Points

which code goes into which class

I don’t understand how it is determined which code goes into the class Example and which goes into the class PezDispenser. I was able to follow the teacher and my code works. But if I worked alone I think I would place more of the code in the main(). How would I know what goes where?

2 Answers

Garrett Carver
Garrett Carver
14,681 Points

That is a common problem a lot of new developers have, so try not to be discouraged! As you learn more about object oriented programming and other common design patterns such as MVC, you'll get more of a feel for what code needs to go where.

Perhaps you'll get some more specific answers, but don't sweat it if you're still struggling. Just keep building up you're experience going through courses and it will suddenly make sense.

Kim Gee
Kim Gee
3,841 Points

Thank you Garrett

This is a great question. I struggle with this a little as well. From what I've gathered is that when making a new method for the PEZ it should go under the PEZ class. When executing the code it should go under the main file which in this case is Example. So I guess you could say Example is like the folder and all the paper inside is the classes. I'm not 100% sure on this but from i gather this seems to be the case.