User Tools

Site Tools


solution_of_4._add_instance_variables_in_the_tree

The Java training online

Back to the table of contents

Solution: 4. Add instance variables in the tree

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

Helping elements

  • to be available in Tree and in SpatializedTree, the new variables should be added in the superclass: Tree: they will be inherited in the subclass.
  • the three getters should be added in the same class, getId ()
  • you may adapt the constructor of Tree to get the 3 extra parameters and store them in the 3 new instance variables like for dbh
  • the toString () method of Tree may be adapted to display the 4 instance variables
  • the toString () method of SpatializedTree relying on its superclass needs no change
  • the code of exercice 1. needs adaptation to match the new constructor of Tree with its 4 parameters

A possible solution

Add instance variables and accessors Terminal output

Back to the table of contents

solution_of_4._add_instance_variables_in_the_tree.txt · Last modified: 2021/12/13 09:28 by 127.0.0.1