Question: Could anyone help me create a subclass from a previous class in Python 3.6.2? Previous class: #Animal.py class Animal: def __init__(self,name,animal_type,mood): self.__name = name self.__animal_type

Could anyone help me create a subclass from a previous class in Python 3.6.2?

Previous class:

#Animal.py

class Animal:

def __init__(self,name,animal_type,mood):

self.__name = name

self.__animal_type = animal_type

self.__mood = mood

def get_animal_type(self):

return self.__animal_type

def get_name(self):

return self.__name

def check_mood(self):

return self.__mood

Task:

Write a class named Mammal that inherits from Animal class that has the following additional attribute and method. This class should be written in the Animal.py file that was written for the previous assignment.

Attributes

__hair_color: 

a hidden attribute used to indicate the color of the mammals hair.

Methods

__init__: 

this method should initialize the two attributes from the Animal class required in the Animal class __init__, the single attribute listed above, and assign their default values.

get_hair_color: 

this method should return the value of the __hair_color field.

Bird Class

Write a class named Bird that inherits from Animal class that has the following additional attribute and method. This class should be written in the Animal.py file that was written for the previous assignment.

Attributes

__can_fly: 

a hidden attribute used to indicate if the bird can fly.

Methods

__init__: 

this method should initialize the two attributes from the Animal class required in the Animal class __init__, the single attribute listed above, and assign their default values.

get_can_fly: 

this method should return the value of the __can_fly field.

Animal Generator Program

Once you have written the Animal class, extend the animalGenerator.py from the previous assignmnet. This program should use Animal.py as a module.

In animalGenerator.py, prompt the user to enter if they would like to create a mammal or a bird.

If the user selects mammal, prompt the user for the name, type of the mammal, and the color of hair. Create a new Mammal object to store this data.

If the user selects bird, prompt the user for the name, type of the bird, and if the bird can fly. Create a new Bird object to store this data.

Finally, then ask the user if they would like to repeat the process. They should be able to create as many Mammal and Bird objects as they would like.

After the user is done creating animals, this program should use the objects accessor methods to retrieve the name, type, and mood of each animal. This information should be formatted and displayed as shown in the sample program output below.

Sample Output

(Input is highlighted in orange)

Welcome to the animal generator! This program creates Animal objects Would you like to create a mammal or bird? 1. Mammal 2. Bird Which would you like to create? 2 What type of bird would you like to create? Penguin What is the bird's name? Peggi Can the bird fly? Yes 
Would you like to add more animals (y/n)? y Would you like to create a mammal or bird? 1. Mammal 2. Bird Which would you like to create? 1  What type of mammal would you like to create? Tiger What is the mammal's name? Truman What color is the mammal's hair? Orange Would you like to add more animals (y/n)? n Animal List ----------- Peggi the Penguin is sleepy Truman the Tiger is hungry 

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!