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 trialCristiano Monteiro
5,942 PointsDispense Method
Would the implementation of the dispense() Method be okay if i do it like this:
public boolean dispense() {
boolean wasDispensed;
if (!isEmpty()) {
mPezCount--;
wasDispensed = true;
}else{
wasDispensed = false;
}
return wasDispensed;
}
instead of : public boolean dispense() { boolean wasDispensed = false; if (!isEmpty()) {
mPezCount--; wasDispensed = true; }
return was Dispensed; }
2 Answers
Brendon Butler
4,254 PointsYes. Your implementation would work. It's just not as clean as doing it the other way. Essentially you're doing the same thing just with a bit more code.
As a programmer, you want to keep your code as clean as possible. That way you won't get confused if you look back on it in the future and so others can read it without any issues. :)
Cristiano Monteiro
5,942 PointsThanks Brendon.