Forums Register Login
Head First Java Chapter 3 Pool Puzzle question
Hi everyone, first time poster here, i'm just having a bit of trouble understanding one small part of this puzzle:

So this puzzle compiles an array of triangles and calculates the area for each, but my question is, how does it know how to calculate the area when the formula is at the very end? Wouldn't it have to be at the beginning of the while loop for it to be taken into account? I've actually reached up to the end of Chapter 5 in the book, hoping that things would start to become more clear but i keep running in to similar confusion where code at the end of my program affects portions at the beginning. Any help would be greatly appreciated!
(1 like)
The first thing you could do to make it clearer is add proper indentation. Then it would be obvious that setArea() is a method just like main() (maybe you already determined that but indentation would make it jump out at you). So, yes, setArea() appears after the place where it is called in main(). The order of methods inside a class makes no difference.
(1 like)
Welcome to CodeRanch  Thank you for posting the code in code tags.
Since this is your first post, I added proper indentation, see It looks more readable now. Rest is cleared by Carey Brown.
Great, I think that clears it up, thanks!
I don't think it matters where you put that method since the main just calls it.
Water proof donuts! Eat them while reading this tiny ad:
Rocket Oven Kickstarter - from the trailboss

This thread has been viewed 178 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 21, 2018 19:30:09.