Someone placed a pair of rabbits in a certain place, enclosed on all sides by
a wall, so as to find out how many pairs of rabbits will be born there
in the course of one year, it being assumed that every month a pair
of rabbits produces another pair, and that rabbits begin to bear young
two months after their own birth.
(Note that Fibonacci assumes that a rabbit pair always
gives birth to a male-female pair.)
How many rabbits will result in a year? Fibonacci calculated the answer and noted there was a pattern to the population growth. The pattern, called the Fibonacci sequence, arises often in biology and botany and is defined by this equation set:
rabbitPairsAtMonth(0) = 1 rabbitPairsAtMonth(1) = 1 rabbitPairsAtMonth(n) = rabbitPairsAtMonth(n-1) + rabbitPairsAtMonth(n-2), when n>1For example, the rabbits after 4 months are calculated as follows:
rabbitPairsAtMonth(4) = rabbitPairsAtMonth(3) + rabbitPairsAtMonth(2)
= (rabbitPairsAtMonth(2) + rabbitPairsAtMonth(1))
+ (rabbitPairsAtMonth(1) + rabbitPairsAtMonth(0))
= ( (rabbitPairsAtMonth(1) + rabbitPairsAtMonth(0)) + 1 ) + (1 + 1)
= ((1 + 1) + 1) + 2 = 5
(By the way, rabbitPairsAtMonth(12) = 233. A bit of history
about Fibonacci can be found at
http://www.austms.org/Modules/Fib)
java RabbitSim.Start
+----------------------------------------+ | Type rabbit lifespan (a positive int): | | | OK Cancel | +----------------------------------------+
+------------------------------------------+ | Type simulation length (a positive int): | | | OK Cancel | +------------------------------------------+and the user types a second int.
Here is an example log file for a simulation where a rabbit has a lifespan of 4 months and the simulation goes for 6 full months:
Month 0: birth of Rabbit.RabbitPair@207402 at 0; pair count = 1 Month 1: Month 2: birth of Rabbit.RabbitPair@a04e24 at 2; pair count = 2 Month 3: birth of Rabbit.RabbitPair@6a5a54 at 3; pair count = 3 Month 4: birth of Rabbit.RabbitPair@504c4b at 4; pair count = 4 death of Rabbit.RabbitPair@207402 at 4; pair count = 3 Month 5: birth of Rabbit.RabbitPair@1c0e07f at 5; pair count = 4 birth of Rabbit.RabbitPair@1d2ef45 at 5; pair count = 5 Month 6: birth of Rabbit.RabbitPair@15aa73b at 6; pair count = 6 death of Rabbit.RabbitPair@a04e24 at 6; pair count = 5 birth of Rabbit.RabbitPair@991f7e at 6; pair count = 6The log must list the births and deaths of all rabbit pairs and keep a running total of the count of living rabbit pairs. Notice that each rabbit pair must be given a name; the cryptic names shown above are generated by a built-in Java method used in the package described below.
Although class RabbitPair can construct rabbit pairs, it does not know how to generate output, and it assumes that someone else (you) will write a class that can do output. The class you write must implement interface MessageBoard, which is a Java interface included within package Rabbit. Here is a picture of the completed application you must build, where your job is to write the components of package RabbitSim and connect them to package Rabbit:
You can download package Rabbit, either in pieces or as a single jar file, at http://www.cis.ksu.edu/~schmidt/300f02/Assign/Assn1![]()
Build and test your work in the above configuration. Remember to insert javadoc-style commentary into your work. When you are satisfied with the results, execute javadoc to generate the web documentation.
jar c Assign1 > Assign1.jar(A jar-file is Java's version of a ``zip'' file; it holds one entire folder in a single file.) See the instructions at http://www.cis.ksu.edu/~schmidt/300f02/Assign/how.to.jar.html for more details.