User Tools

Site Tools


solution_of_5._add_methods_in_the_tree

The Java training online

Back to the table of contents

Solution: 5. Add methods in the tree

Try to work with the helping elements before looking at the solution…

Helping elements

  • the 2 methods should be added in Tree, they will be inherited and available in SpatializedTree
  • These 2 methods rely on existing instance variables, so no new instance variable is needed
  • to avoid an integer division in getCrownBaseHeight(), make sure to write 2d / 3d (if the 2 operands of a division are integers, only the integer part is kept in the result: 2 / 3 = 1, but 2d / 3d = 1.5)
  • adapt toString () in Tree to display the crownRadius and crownBaseHeight values
  • use NumberFormat to display 1.12 instead of 1.119999999999, see the online javadoc for NumberFormat, try to have the english . decimal separator

A possible solution

Add extra methods in Tree Output before NumberFormat Example of code with NumberFormat Result with NumberFormat

Back to the table of contents

solution_of_5._add_methods_in_the_tree.txt · Last modified: 2021/12/13 09:28 by 127.0.0.1