Question: continuing to work on the Habitat class, a static int constant MAX _ HABITATS has been defined and initialized. Define a public static array of
continuing to work on the Habitat class, a static int constant MAXHABITATS has been defined and initialized. Define a public static array of Habitat field habitats. Create a public numberOfHabitats counter to keep track of the number of habitats, too. You are given the code of the constructors as well. Make sure they register the new instances of the Habitat class. Do not modify their visibility modifiers or their parameters. Finally, create a static method printHabitats that prints all habitats to screen.
Make sure the output follows the format of the sample run. For simplicity, convert the surfaceArea to int when printing out the habitat.
Note: Assume the number of created habitats will never exceed MAXHABITATS.
Sample Run
Habitats
Max Population:
Animal Size: Small
Animal Diet: Herbivore
Surface Area: m
Max Population:
Animal Size: Medium
Animal Diet: Omnivore
Surface Area: m
private Habitatint maxPopulation, char animalSize, char animalDiet, double surfaceArea
this.maxPopulation maxPopulation;
this.animalSize animalSize;
this.animalDiet animalDiet;
this.surfaceArea surfaceArea;
Habitat
reset;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
