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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started