Question: Write a Java program to simulate an ecosystem containing two types of creatures, bears and fish . The ecosystem consists of a river, which is

Write a Java program to simulate an ecosystem containing two types of creatures, bears and fish . The ecosystem consists of a river, which is modeled as a relatively large array (i.e. 500 cells). Each cell of the array should contain an Animal object, which can be a bear, a fish, or null . Initialize the array to randomly contain these three types. In each time step, based on a random process, each bear/fish either attempts to move into an adjacent array cell or stay where it is. If two animals of the same type are about to collide in the same cell, then they stay where they are, but they create a new instance of that type of animal, which is placed in an empty (i.e. previously null ) cell in the array. If a bear and a fish collide, then the fish dies (i.e., it disappears). Provide summary information on the array after each time step (time step number and how many bears, fish, and null ). Run the simulation until the ecosystem contains all bears.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!