The Java training online

Back to the table of contents

5. Add methods in the tree

Purpose: Choose where methods should be added in an inheritance graph

Statement of the exercise:

  1. Add 2 methods in the tree, getCrownRadius() returning dbh / 5 and getCrownBaseHeight() returning 2 / 3 * height
  2. Adapt Tree.toString() to display the crownRadius and crownBaseHeight

Helper and solution

Back to the table of contents