Checkpoint 2

Now we want to try some more interesting models of rabbit populations.

Do this first

The model used by the simulator is required to be a class named RabbitModel, so in order to implement a model with different behavior, you'll have to make the modifications in your RabbitModel. Before you begin doing so, save your work as follows:
  1. Run your application and take a screenshot of the population plot.
    • On Windows, use Alt-Printscreen to save a screenshot to the clipboard. Then open the Paint program and select to Edit->Paste. Then save the image to your network drive so you can show the TA later.
    • On a Mac, make the plotter window active and hit Command-Shift-4. Press the spacebar to select the window, and then click to take a screenshot. You can normally find the image file on your desktop.
  2. Save a copy of your code. This is easy to do in Eclipse.
    1. Select your RabbitModel class in the Package Explorer
    2. Hit Control-C (to copy) and then Control-V (to paste the copy into the same package)
    3. When prompted, enter a new name for the copy, such as RabbitModel2, RabbitModel3, and so on.
(Later in the semester we will learn how to use java interfaces to avoid having to specify the exact class name like this.)

Models to implement

Complete the following models. As you complete each one, follow the steps above for saving a screenshot of the plot and a copy of your code. When you are done, show your TA the screenshots and code for the four models.

  1. The population starts at zero and increases each year by 1 rabbit, but after every 5 years, oversaturation brings the population back down to 0. (Hint: consider an expression using the mod operator "%". If you divide the population by 5, what is the remainder?)
  2. The population starts at 500 and decreases by half each year.
  3. The increase in population each year is a random value in the range 0 through 9.
  4. The population follows the Fibonacci sequence, in which the current population is the sum of the previous two years' populations. Assume it starts out with value 1 for the last year's population and 0 for the year before that, so that the initial population is also 1 + 0 = 1. For example, the values would look like this for the first few years:
    Initial values:
    last year1
    year before0
    population1 = 1 + 0
    After one year:
    last year1
    year before1
    population2 = 1 + 1
    After two years:
    last year2
    year before1
    population3 = 2 + 1
    After three years:
    last year3
    year before2
    population5 = 3 + 2

    To get this working, you'll just need two extra instance variables (for example, lastYear and yearBefore) that are updated as indicated in the sample values above.