AMAPstudio

User Tools


The Java training online

Back to the table of contents

6. Write a method to create a list of trees

Purpose: Write a method returning a list, write a loop, use a random number generator.

Statement of the exercise:

  1. the method takes 3 arguments: the expected number of trees, and the size of the rectangle for the trees coordinates x and y (in meters)
  2. the ids of the trees are unique, between 1 and number of trees
  3. their age is randomly chosen between 1 and 25
  4. their height is age / 2
  5. their dbh is age
  6. the tree positions must be randomly chosen in the given rectangle
  7. add code in the main method of exercise 1 to build a list of 10 trees and add a loop to display the result of their toString() method

Helper and solution

Back to the table of contents

6._write_a_method_to_create_a_list_of_trees.txt ยท Last modified: 2021/01/26 09:28 by coligny