Use and Modify the Code a Bit
- Now back in the genetic.java file, look at two bits of code.
- The first is main at the bottom of the file. That's
where all the code runs. Note the hello world and goodbye cruel
world bits that start and end the program.
- The second is at the top of the code, GENERATIONS_TO_RUN. This
is a named constant that is used in main to, as it describes, set
how many generations are set to run. Change it from 40 to 2.
- Then run it.
- You should see three sets of populations, the initial one,
after one generation, and then after two generations. Note that
it's also printing out the sum of the digits for each member.
- What the system is currently trying to do is find the largest digit
string.
- Note how the first one has some relatively low totals, and it more
or less gets better (closer to 90) each generation.
- Now change GENERATIONS_TO_RUN back to 40 and see how many
of the members are 90 or close to 90. See how many genes are 9s.
- If you get here, you can again look about while the rest of us get here.
In particular, you might want to look at the getNextGeneration function.