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 namedRabbitModel
, 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:
- 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.
- Save a copy of your code. This is easy to do in Eclipse.
- Select your
RabbitModel
class in the Package Explorer - Hit Control-C (to copy) and then Control-V (to paste the copy into the same package)
- When prompted, enter a new name for the copy, such as
RabbitModel2
,RabbitModel3
, and so on.
- Select your
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.
- 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?)
- The population starts at 500 and decreases by half each year.
- The increase in population each year is a random value in the range 0 through 9.
- 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 year 1 year before 0 population 1 = 1 + 0 After one year: last year 1 year before 1 population 2 = 1 + 1 After two years: last year 2 year before 1 population 3 = 2 + 1 After three years: last year 3 year before 2 population 5 = 3 + 2 To get this working, you'll just need two extra instance variables (for example,
lastYear
andyearBefore
) that are updated as indicated in the sample values above.