User Tools

Site Tools


2._create_a_tree_class

The Java training online

Back to the table of contents

2. Create a Tree class

Purpose: Write a complete class to describe a simple tree object.

Statement of the exercise:

  1. Add a new class in the training package, the class is named Tree, with a single instance variable named dbh, in centimeters (diameter at breast height is the main dimension of a tree for foresters). Add a constructor taking dbh in argument, a getter for the dbh variable and a toString() method displaying the tree dbh.
  2. Add code in the main method of exercise 1. to create a tree with dbh 5.6cm and print its toString() method to the terminal

Helper and solution

Back to the table of contents

2._create_a_tree_class.txt ยท Last modified: 2021/12/13 09:28 by 127.0.0.1