Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please use in Java For the first example, we will create a very simple model in which . The population is initially two, one new

image text in transcribedplease use in Javaimage text in transcribedimage text in transcribed

For the first example, we will create a very simple model in which . The population is initially two, one new rabbit is born each year, and no rabbits ever die. To implement this simple model, your class really only needs one instance variable, representing the current population of rabbits. 1. Add a private int instance variable to your RabbitModel. 2. In the constructor, initialize this variable to 2. 3. In the simulateYear method, increment this variable by 1 to simulate the passing of one year. 4. In the reset method, set this variable back to the initial value 2. (Note that this reset always does the exact same work as the constructor, so in more complex models you can save yourself some effort by just calling reset in your constructor.) More generally, the simulateYear method could alter the population according to weather, pesticide usage, traffic, predators, butterflies in Brazil, etc. For the checkpoints, you will revise this code to create more complex models. Complete the following models. As you corriplete 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 surri of the previous two years' populations. Assume it starts out with value 1 for the last year's population and 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 o 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, lastrea and vorherare, that are updated as indicated in the sample values above. package lab2; * A Rabbit Model is used to simulate the growth * of a population of rabbits. */ public class RabbitModel // TODO add instance variables as needed * Constructs a new RabbitModel. */ public RabbitModel() { // TODO } /** * Returns the current number of rabbits. * @return current rabbit population */ public int getPopulation () { // TODO - returns a dummy value so code will compile return 0; } ** * Updates the population to simulate the * passing of one year. * public void simulateYear() { // TODO } * Sets or resets the state of the model to the * initial conditions. * public void reset () // TODO } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

What is a board of directors?

Answered: 1 week ago

Question

1. Traditional and modern methods of preserving food Articles ?

Answered: 1 week ago

Question

What is sociology and its nature ?

Answered: 1 week ago

Question

What is liquidation ?

Answered: 1 week ago

Question

Explain the different types of Mergers.

Answered: 1 week ago