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 trialJohn Sherwin
Courses Plus Student 6,578 Pointsthe "if" statement
I was confused in the "load(int pezAmount)" method. Is the "mPezAmount = newAmount" the "else" in the if statement?
1 Answer
jcorum
71,830 Points1 if (newAmount > MAX_PEZ) {
2 throw new . . . ;
3 }
4 mPezCount = new Amount;
5 . . .
Technically line 4 is not the else... for the if... statement, because there is no else.... But from the practical point of view, yes, it could be considered such. If newAmount is greater than MAX_PEZ the program throws an exception and stops. If it's not, then the flow of control goes from line 1 to line 4. The code could be rewritten to put what follows in an else { . . . } statement, but for many that just makes it more complicated.