This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Head First Java Chapter 3 Pool Puzzle question  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Bartender
Posts: 4522
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Staff note (Knute Snortum):

The code in the post above was edited so that it now has good indentation.

 
Saloon Keeper
Posts: 927
32
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stefan Moreno
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, I think that clears it up, thanks!
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it matters where you put that method since the main just calls it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!