Question: Need help with Inheritance, composition, and polymorphism. PYTHON 3 ONLY!!! Do the following exercises: 1. Write a class named Bird that has a method named

Need help with Inheritance, composition, and polymorphism. PYTHON 3 ONLY!!!

Do the following exercises:

1. Write a class named Bird that has a method named call. The call method should return the string "chirp". Next, write a class named Duck that inherits from Bird and overrides the call method to return "quack".

2. Write a class named Employee that has two data members: name and salary. It should have a constructor that takes two parameters and uses them to initialize its data members. It should also have a method named grossMonthlyPay that returns 1/12 of the Employee's salary. Next, write a class named SeniorEmployee that inherits from Employee and overrides grossMonthlyPay to add a $500 bonus - use super() to call the Employee version of the method and then add $500 to that.

3. For this exercise, you'll use the Rectangle class below (you can assume that the length and width are measured in feet):

class Rectangle:

"""

Represents a geometric rectangle

"""

def __init__(self, length, width):

self.length = length

self.width = width

def area(self):

return self.length * self.width

def perimeter(self):

return 2 * self.length + 2 * self.width

Write a class named Carpet that has two data members: size and costPerSqFoot. It should have a constructor that takes a Rectangle object and a float as parameters and uses them to initialize its data members. It should also have a method named cost that asks the size data member for its area and uses that to calculate and return the cost of the Carpet. This is an example of class composition because the Carpet class contains a Rectangle object as one of its data members.

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!