The Java training online
Try to work with the helping elements before looking at the solution…
Helping elements
createTrees()
int numberOfTrees
, double xSize
and double ySize
SpatializedTree
instances, it could be added in SpatializedTree
and be public
and static
for a convenient usestatic
if it needs only its parameters to be run, which is the case here, it will be called this way: List treeList = SpatializedTree.createTrees (n, xSize, ySize);
(list in java.util
)Random random = new Random ();
java.util.ArrayList
classfor (int i = 0; i < numberOfTrees; i++) {
id
(e.g. id = i + 1;
), age
, height
, dbh
, x
and y
0
and n
, use random.nextInt (n);
0
and n
, use random.nextDouble() * n;
list.add(tree);
A possible solution