Question: Write a class named Pet, with should have the following data attributes: 1._name (for the name of a pet. 2._animalType (for the type of animal
Write a class named Pet, with should have the following data attributes:
1._name (for the name of a pet.
2._animalType (for the type of animal that a pet is. Example, values are "Dog","Cat" and "Bird")
3._age (for the pet's age)
The Pet class should have an __init__method that creates these attributes. It should also have the following methods:
-setName -This method assigns a value to the_name field
-setAnimalType - This method assigns a value to the __animalType field
-setAge -This method assigns a value to the __age field
-getName -This method returns the value of the __name field
-getAnimalType -This method returns the value of the __animalType field
-getAge - This method returns the value of the __age field
Write a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This should be stored as the object's attributes. Use the object's accessor methods to retrieve the pet's name, type and age and display this data on the screen. Also add an __str__ method to the class that will print the attributes in a readable format. In the main part of the program, create two more pet objects, assign values to the attirbutes and print all three objects using the print statement.
Note: This program must be written using Python language
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
