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 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,680 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.