68.3k views
10 votes
Create a Pet class that keeps track of the name, age, weight, type of animal, and breed for records at an animal clinic with 2 constructors, accessor (get) methods, a toString method, and mutator (set) methods for each instance variable.

User Sucotronic
by
4.4k points

1 Answer

9 votes

Answer:

class Pet():

def __init__(self, name, age, weight, animal_type, breed):

self.name = name

self.age = age

self.weight = weight

slef.aT = animal_type

self.breed = breed

def set_name(self, name):

self.name = name

def get_name(self):

return self.name

def set_age(self, age):

self.age = age

def get_age(self):

return self.age

def set_weight(self, weight):

self.weight = weight

def get_weight(self):

return self.weight

def set_Type(self, type):

self.aT = type

def get_Type(self):

return self.aT

def set_breed(self, breed):

self.breed = breed

def get_breed(self):

return self.breed

def toString(self):

print(f"The pet {self.name} is {self.age} year old and weighs {self.weight}lbs. The pet is a {self.breed} breed of {self.aT}.")

Step-by-step explanation:

The python program defines a class called Pet that has five features namely name, age, weight, animal_type, and breed of the animal. The set and get methods of the class are the mutators and accessor respectively. The final method of the class is the 'toString' method that prints the summary of the Pet object instance.

User Daniel Lord
by
3.7k points