Question: Part B: Inheritance ( 1 0 Pts ) Instructions: ( pets . py ) In this part, you will write 2 classes ( Dog and

Part B: Inheritance (10 Pts)
Instructions: (pets.py)
In this part, you will write 2 classes (Dog and Panda) that inherit all the functionalities from the Animal class and add some more.
Task 1: Dog Class
It represents a dog entity with specific attributes and behavior. It is a subclass of class Animal that should include the following additional attributes and methods:
Attributes:
-In addition to the attributes inherited from the Animal class (i.e.,x, y, id, and species), the Class should have the following attributes:
name: The dogs name. Default is "Dogzilla".
gender: The dogs gender. Default is "Female".
Methods:
__init__() method: Accepts six arguments: self, name (default "Dogzilla"), gender (default "Female"), x (default 0), y (default 0), id (default 100) in this order. It uses the constructor for class Animal to store species ("Dog"), x, y, andid as data attributes. Hint: check out how MassParticle calls the Particle __init__ in Code Listing 12.11
# Example usage:
animal = Dog("Dogzilla", "Female", 0,0,100)
print(animal) # Animal Dog (ID: 100) is at (0,0)
about() method: Accepts one argument: self. It Returns a string introducing the dog, including its name and position. Additionally, it identifies the dog as a race watcher.
# Example usage:
animal = Dog()
animal.about()
'''
Hi my name is Dogzilla.
Animal Dog (ID: 100) is at (0,0).
I'm your female dog race watcher.
'''
Task 2: Panda Class
representing a panda entity where you should be able to decide on the name/gender of your Panda. You can also interact with it by feeding your Panda, playing with your Panda, and talking to your Panda. It is a subclass of class Animal that should include the following additional attributes and methods:
Attributes:
-In addition to the attributes inherited from the Animal class (i.e.,x, y, id, and species), the Class should have the following attributes:
name: The pandas name.
gender: The pandas gender.
fur_color: The pandas fur color.
As well as some other attributes that are related to physical/mental health status:
hunger
thirst
loneliness
Methods:
__init__() method: Accepts seven arguments: x (default 0), y (default 0), id (default 0), name (default "Fluffy"), gender (default "Unknown"), and fur_color (default "Red").
It uses the constructor for class Animal to store species ("Panda"), x, y, andid as data attributes.
When a Panda object is created, his/her initial status have a hunger and thirst level of 0. Their loneliness is at 10.
Once all attributes are initialized, a message is printed from the animals TALKS dictionary with a newborn message (TALKS[newborn]).
# Example usage:
animal = Panda(0,0,10, "Fluffy", "male", "Red")
# Hi master, my name is Fluffy.
print(animal)
# Animal Panda (ID: 10) is at (0,0)"
status() method: prints a string representation of the Pandas status.
# Example usage:
animal = Panda(0,0,10, "Fluffy", "male", "Red")
animal.status()
'''
Panda Fluffy (ID: 10, Gender: male, Fur Color: "Red")
Position: (0,0)
Hunger: 0, Thirst: 0, Loneliness: 10
'''
reply_to_master() method: accepts as argument event. It prints a reply to the master based on the Pandas mood and status , such as hunger, thirst, and loneliness.
event is a key that determines which specific message from the animals TALKS dictionary to use for its initial reply. It first prints the animals name followed by the message tied to the given event.
Then, it evaluates the animals attributes:
Hunger (hunger) and Thirst (thirst): If both exceeds or equal 7, the animal replies with a tired message (TALKS[tired]).
Hunger (hunger): If greater than or equal to 5 the animal replies with a hunger messages (TALKS[hunger]).
Thirst (thirst): If greater than or equal to 5, the animal replies with a thirsty messages (TALKS[thirsty]).
Loneliness (loneliness): If greater than or equal to 7, the animal replies with a loneliness message (TALKS[loneliness]).
If none of the above conditions are met, the animal replies with a default message (TALKS[default]).
# Example usage:
animal = Panda(0,0,10, "Fluffy", "male", "Red")
animal.reply_to_master('play')
'''
Fluffy: Happy to have your company ~
Fluffy: Could you stay with me for a little while ?
'''
animal.hunger =10
animal.reply_to_master('feed')
'''
Fluffy: Yummy !
Fluffy: I'm too hungry or thirsty to talk right now...
'''
play() method: This method does not take any parameter. It will update the loneliness attribute. It Reduces loneliness by 3 but increases hunger and thirst slightly by 3. It ensures that loneliness does not go below 0 and that hunger and thirst does not go above 10.
It will then call the reply_to_master() method with the 'play' event.

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 Programming Questions!