15-110 FALL 2009 [CORTINA]

LAB 1: Data types, variables, and operators

The growth in a population can be modeled using the logistic method. In this method, the population growth is limited by various resources (food, shelter) to some carrying capacity. The carrying capacity is the maximum number of a species that can be supported by the region.

The increase in population I for one year is given by the equation

rN((K-N)/K)

where
r = the annual growth rate (assuming no limits on population growth)
N = the current population size at the beginning of the year
K = the carrying capacity of the region

For example, if you have an initial herd of N = 100 deer that have an annual growth rate of r = 0.5 (50% increase in one year) in a park that can support K = 500 deer, then the deer will increase in population as follows:

N (at start of year)   I (increase in population)   N (at end of year) 
100.0                  40.0                         140.0 
140.0                  50.4                         190.4 
190.4                  58.94784000000001            249.34784000000002 
249.34784000000002     62.499574687334395           311.84741468733444 
311.84741468733444     58.674897296492894           370.5223119838273 
370.5223119838273      47.974372314072994           418.4966842979003 
418.4966842979003      34.108867380613724           452.605551678514 
452.605551678514       21.450990429044985           474.056542107559 
474.056542107559       12.298665938803648           486.35520804636263 
486.35520804636263     6.6362156293606365           492.9914236757233 

Notice that as the population approaches the carrying capacity, the annual increase begins to slow down so that the species does not become over-populated for the given region.

EXERCISES

  1. Using Eclipse, write a simple Java program in a project named Lab1 that contains a class named PopulationAnalyzer with a single main method as follows:

    1. Declare variables for the population, growth rate, carrying capacity and increase in population. Use names for these variables that are self-explanatory (e.g. population instead of P). Choose appropriate types for each variable.

    2. Initialize the variables for the values for the deer population in the example above. (You do not need to use any instructions to read the data from the keyboard at this time.)

    3. Compute and output the population of the deer after each year for 10 years. Do this for one year first to make sure you're doing the computation correctly. Then modify the code so that ten years are output. Your output might look something like this:

      DEER POPULATION 
      Annual Growth Rate: 0.5 
      Carrying Capacity: 500 
      Initial Population: 100.0 
       
      GROWTH OF POPULATION OVER 10 YEARS: 
      140.0 
      190.4 
      249.34784000000002 
      311.84741468733444 
      370.5223119838273 
      418.4966842979003 
      452.605551678514 
      474.056542107559 
      486.35520804636263 
      492.9914236757233 
      

    4. Experiment with the growth rate and see what happens to the output. What happens if the growth rate is 75%? 150%?

  2. Once you get the program above to work correctly, modify the program to output the number of deer rounded to the nearest integer.

    HINT: Add 0.5 to the resulting population first and then truncate it to an integer using type-casting when you display it. Why does this work?

    NOTE: Make sure you use the original population value for your next calculation, not the rounded value, otherwise you will get different answers since you'll be using different values in the formulas for subsequent years.

HANDIN

At the end of lab, create a zip file of your program and submit it to the handin server http://handin.intro.cs.cmu.edu/v1.