Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions