Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Scenario A wildlife preservation society wants to observe brown bears' feeding and hibernation behaviour and establish the frequency of each type of food consumed by
Scenario A wildlife preservation society wants to observe brown bears' feeding and hibernation behaviour and establish the frequency of each type of food consumed by these bears.
This scenario is modelled in Java by an abstract class Bear click here to view this class which provides attributes and operations common to all types of bear, and BrownBear, which will be a subclass of Bear.
STUDENTusername
Develop only the class BrownBear.
The superclass Bear is provided already in the testing environment. Do not duplicate code from this class in the BrownBear class.
A partial implementation of BrownBear is provided in the answer box below that already has fields hibernating of type boolean and name of type String as well as getter and setter methods for these.
a Amend the header of class BrownBear in the answer box below, to make it a subclass of Bear.
b Add a public constructor for BrownBear. It should initialise:
name from the received parameter
species to "Brown Bear"
habitat to "Asia"
hibernating to false.
height to
c Add a public method addfood that adds a food to foods. The method receives a String parameter representing the food and does not return a value.
d Add a public method foodFrequency that returns an int representing how many times the food passed as a parameter occurs in foods.
e Override the Bear toString method so that depending on the value of hibernating it appends either:
and is hibernating"
or
and is not hibernating"
and then the name of the bear.
For example, for a nonhibernating Brown Bear named Fuzzy whose habitat is Asia the method should add:
A bear of species Brown Bear which lives in Asia and is not hibernating
Name: Fuzzy
to the string returned by the Bear toString method.
f Override the equals method inherited from Bear so that it returns true if the objects compared are the same class or subclass and their species and name are the same.STUDENTusername
Answer:penalty regime:
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