Question
Java need help writing this class Constructor and Description Animal(int sleepHungerIn, int sleepHappinessIn, int cleanHappinessIn) Animal Constructor, creates a new animal that starts of with
Java need help writing this class
Constructor and Description Animal(int sleepHungerIn, int sleepHappinessIn, int cleanHappinessIn) Animal Constructor, creates a new animal that starts of with maximum hunger and happiness values (100 is the max for both).
Method Summary
Modifier and Type Method and Description abstract void clean() The Animal's cage is cleaned.
void eat(Food meal) Method called to feed an Animal.
int getCleanHappiness() Getter to retrieve the amount of change in happiness this Animal experiences when getting a cleaned cage
. int getHappiness() Retrieves the current happiness value of the Animal.
int getHunger() Retrieves the current hunger value of the Animal.
int getSleepHappiness() Getter to retrieve the amount of change in happiness this Animal experiences during sleep.
int getSleepHunger() Getter to retrieve the amount the change in hunger this Animal experiences during sleep.
void modifyHappiness(int happinessModifier)
Modifies this Animals' happiness by the amount specified.
void modifyHunger(int hungerModifier) Modifies this Animals' hunger by the amount specified.
void setFoodBehaviors(FoodMappings foodBehaviorsIn) Updates the food behaviors for this animal object based on the provided mappings.
abstract int sleep() The Animal sleeps for the night.
java.lang.String toString() String representation of the Animal.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Constructor Detail
Animal
public Animal(int sleepHungerIn, int sleepHappinessIn, int cleanHappinessIn) Animal Constructor, creates a new animal that starts of with maximum hunger and happiness values (100 is the max for both). It also will use the provided parameters as the values for adjusting state during sleep and cage cleaning in the future.
Parameters: sleepHungerIn - Amount of hunger increases while sleeping. sleepHappinessIn - Amount of happiness lost when sleeping. cleanHappinessIn - Amount of happiness gained when cage is cleaned.
Method Detail
setFoodBehaviors
public void setFoodBehaviors(FoodMappings foodBehaviorsIn) Updates the food behaviors for this animal object based on the provided mappings.
Parameters: foodBehaviorsIn - Describes the nutrition and happiness behaviors of this animal.
getHunger
public int getHunger() Retrieves the current hunger value of the Animal. Hunger is measured on an inverted scale of 100 (not hungry at all) to 0 (most hungry possible), inclusive.
Returns: Animal's hunger value.
getHappiness
public int getHappiness() Retrieves the current happiness value of the Animal. Happiness is measured on a scale of 0 (very unhappy) to 100 (maximum happy), inclusive.
Returns: Animal's happiness value.
getSleepHunger
public int getSleepHunger() Getter to retrieve the amount the change in hunger this Animal experiences during sleep.
Returns: sleep hunger value of the Animal.
getSleepHappiness
public int getSleepHappiness() Getter to retrieve the amount of change in happiness this Animal experiences during sleep.
Returns: sleep happiness value of the Animal.
getCleanHappiness
public int getCleanHappiness() Getter to retrieve the amount of change in happiness this Animal experiences when getting a cleaned cage.
Returns: happiness from cleaning value of the Animal.
toString
public java.lang.String toString() String representation of the Animal. See example for format. Happiness and hunger values are formatted to width of 3.
Overrides: toString in class java.lang.Object Returns: String of the Animal.
modifyHunger
public void modifyHunger(int hungerModifier) Modifies this Animals' hunger by the amount specified. Resulting state will never be outside the range [0-100].
Parameters: hungerModifier - Value to add to hunger.
modifyHappiness
public void modifyHappiness(int happinessModifier) Modifies this Animals' happiness by the amount specified. Resulting state will never be outside the range [0-100].
Parameters: happinessModifier - Value to add to happiness.
eat
public void eat(Food meal) Method called to feed an Animal. Determines the specific type of Food being fed and modifies the Animal's hunger by multiplying the Food's nutrition value by the Animal's nutrition multiplier for that Food using the modifyHunger method. Modifies the Animal's happiness value by its happiness value for that Food.
Parameters: meal - The Food being fed to the Animal.
sleep
public abstract int sleep() The Animal sleeps for the night. To perform different actions for each animal.
Returns: The score gained for the Animal for the day which is the sum of its hunger and happiness.
clean
public abstract void clean() The Animal's cage is cleaned. Different effects depending on the specific animal.
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