The Capsis training online
Try to work with the helping elements before looking at the solution…
Helping elements
regeneration ()
in the model class: TraModel
capsis4/src/training/
, open it in your text editorregeneration(TraScene newScene)
, it may return void
TraModel.processEvolution ()
, after the growth of the trees (thus, the added trees will only grow next year)regenerationMax
can be declared as a local variable in the method, with a value of 10regenerationMax
can be declared instead as a public
instance variable in the TraInitialParameters
class, now part of the initial parameters to be chosen by user at simulation initialisation time, with its default value of set to 10 (below growthP4
), and the training.gui.TraInitialDialog
must be adapted to ask the user a value for it. You can make it by analogy with growthP4
: each line / section for growthP4
should be followed by a line / section for regenerationMax
. All new keys sent to the user interace with Translator.swap ()
statements must be translated in english and french in resp. capsis4/src/training/TraLabels_en.properties
and TraLabels_fr.properties
// beware in okAction (), regenerationMax is not a double like gp4: double gp4 = TextFieldChecker.getPositiveDoubleValue(growthP4, Translator.swap("TraInitialDialog.growthP4")); // A possible check for the user value of rm: int rm = TextFieldChecker.getPositiveIntValue (regenerationMax, Translator.swap("TraInitialDialog.regenerationMax"))
private Random random;
random = new Random ();
, now random can be used in all methods to draw random numbersThe java random numbers generator
Random
is a random number generator. an import java.util.Random
is needed.
It can be asked random ints or random doubles by calling nextInt(n)
: returns a value between 0 included and n excluded, or nextDouble()
: returns a double value between 0 included and 1 excluded (uniform distribution)
random = new Random ()
random.nextInt(n)
random.nextInt(regenerationMax) + 1
random.nextDouble ()
random.nextDouble () * xSize
originX + random.nextDouble () * xSize
double proba = random.nextDouble ();
# between 0 and 1 (1 excluded)numberOfTrees
to be added, in [0, regenerationMax], make a loop from 1 to numberOfTrees
x
and y
coordinates for the tree (z
is 0 here)Origin and size of the scene
getOrigin ()
: returns an instance of Vertex3d
with x
, y
and z
of the point with the lower (x, y) coordinatesgetXSize ()
and getYSize ()
return the size of the scene along resp. the x
coordinates axis and the y
axisimport jeeb.lib.util.Vertex3d;
Vertex3d origin = newScene.getOrigin ()
, double xSize = newScene.getXSize ()
…double x = origin.x + random.nextDouble () * xSize;
TicketDispenser
class to get unique ids: use the existing treeIdDispenser
of TraModel
to get a new id each time you need: int newId = treeIdDispenser.next ()
crownBaseHeight
and crownRadius
, in meters, and possibly age = 1
…), to create a new Tree, use TraTree's constructor and pass it the expected values in order like this:TraTree t = new TraTree (id, newScene, age, height, dbh, crownBaseHeight, crownRadius, x, y, z);
newScene.addTree (t);
A possible solution