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 Exceptions

Is it necessary to create the newAmount variable?

The same was accomplished if I replaced newAmount=mPezCount+pezAmount with mPezCount=+pezAmount;

Is that a valid way to go about it or will I run into problems eventually?

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

I have two answers for you that may seem contradictory:

  1. Yes, that is a valid way to it. There is often more than one way to program something. Sometimes a problem is better suited to one solution then another, other times it's more which style you're comfortable with.

  2. Yes, you will get into trouble later doing it that way. As I recall, you'll also be checking to see if you'd be overfilling the dispenser. It helps in that case to check the amount first before storing it.