(Solved) : P 231 Write Java Program Simulate Ecosystem Containing Two Types Creatures Bears Fish Ecos Q35073361 . . .

P-2.31 Write a Java program to simulate an ecosystem containingtwo types of creatures, bears and fish. The ecosystem consists of ariver, which is modeled as a relatively large array. Each cell ofthe array should contain an Animal object, which can be a Bearobject, a Fish object, or null. In each time step, based on arandom process, each animal either attempts to move into anadjacent array cell or stay where it is. If two animals of the sametype are about to collide in the same cell, then they stay wherethey are, but they create a new instance of that type animal, whichis placed in a random empty (i.e., previously null) cell in thearray. If a bear and a fish collide, however, then the fish dies(i.e., it disappears). Use actual object creation, via the newoperator, to model the creation of new objects, and provide avisualization of the array after each time step.

P-2.32 Write a simulator as in the previous project, but add aboolean gender field and a floating-point strength field to eachAnimal object. Now, if two animals of the same type try to collide,then they only create a new instance of that type of animal if theyare of different genders. Otherwise, if two animals of the sametype and gender try to collide, then only the one of largerstrength survives

Expert Answer


interface Animal {
        public String getAnimalName();
}

class Fish implements Animal {