Question: Java | The Animal class' field hungerLevel starts at 0 and has a minimum of 0 and maximum of 1 0 using the setter to

Java | The Animal class' field hungerLevel starts at 0 and has a minimum of 0 and maximum of 10 using the setter to enforce this rule by either setting the hungerLevel to 0 if less than 0 or to 10 if more than 10. sleep and roam each print something and increase the hungerLevel, roam increases hungerLevel by 1 whilst sleep increases hungerLevel to 10. sleep should print "sleeping..." and roam should print "moving around..." both should print a newline at the end. Canine should have roam print "like canines roam in packs..." and increase hungerLevel by 1. Feline should print "felines like to roam alone..." and increase hungerLevel by 1; sleep should print "taking a cat nap..." and increase hungerLevel to 10 with makeNoise printing "meow...". Dog should have play print "runs..." and beFriendly should print "nuzzles...". In the habitat class the animals are stored in an ArrayList of type Animal, testAnimal should do the following, print the habitats name, latitude, longitude, number of animals in the habitat, each with a newline afterwards. Then loop through the list of animals and for each animal, do the following in a for-each loop, sleep, make noise, eat, and roam, if the animal is a pet then have it play then be friendly utilizing instanceof to determine if the animal is a pet or not. Finally in the main method of Demo.java in the client package create a habitat, add atleast 1 of every animal, and call testAnimals.
 Java | The Animal class' field hungerLevel starts at 0 and

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!