Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in Python: goal of this program is understand the importance of using inheritance and polymorphism , I have to derive two classes from

Need help in Python: goal of this program is understand the importance of using inheritance and polymorphism , I have to derive two classes from the Policy class, one to add specific risk factors for calculating premiums for a life insurance policy and the other to add the specific risk factors for an automobile policy. Class specifications: I have already written the policy class and the insurance policy class but it has some errors. Need help with automobile class.

Class specifications:

AutomobilePolicy class(this will be a derived class from your Policy class)

Attributes:(we do not need to repeat the attributes of the base class here)

Number of tickets in the last three years

Number of accidents in the last three years

Age risk (a string of Low, Medium, or High)

Methods:

Constructor that receives the same parameters the Base constructor receives and as well as the values for this classes attributes. The constructor will call the base class constructor and then initialize its own attributes with the passed in values.

Get and set methods for all attributes of this class

__str__

Calls the base str method and returns a string containing labels and data for all the attributes.

CalculatePremium

Will calculate the premium and store the result in the Policy class's premium attribute based on the following:

Add an additional amount to the base premium dependent on the following:

Number of tickets is between 0-2 add $25

Number of tickets is between 3-4add $50

Number of tickets over 4 add $100

Number of accidents is between 0-1 add nothing

Number of accidents is between 2-3add $50

Number of accidents over 3 add $100

Age risk factorLow add nothing

Age risk factor Medium add $40

Age risk factor High add $120

The base Policy class is as below:

class Policy:

def __init__(self, policyN, policyO, cadd, prem=0.0,policyD =" "):

self.policyNumber = policyN

self.policyOwner = policyO

self.premium = prem

self.policyissusancedate = policyD

self.policyowneraddress = cadd

def getPolicyNumber(self):

return self.policyNumber

def getPolicyOwner(self):

return self.policyOwner

def setPolicyNumber(self, s):

self.policyNumber = s

def setPolicyOwner(self, s):

self.policyOwner = s

def getPremium(self):

return self.premium

def setPremium(self, f):

self.premium = f

def getPolicyissusancedate(self):

return self.policyissusancedate

def getPolicyowneraddress(self):

return self.policyowneraddress

def setPolicyissusancedate(self,s):

self.setPolicyissusancedate = s

def setPoloicyowneraddress(self,s):

self.setPoloicyowneraddress = s

def __str__(self):

s ="Policy Number - "+self.getPolicyNumber()+" Policy Owner - "+self.getPolicyOwner()+" Premium - "+str(self.getPremium())+" Policy issuance date-"+str(self.getPolicyissusancedate())+" Policy holder's address -"+self.getPolicyowneraddress()

return s

Life insurance.py

import policy from policy

class LifeinsurancePolicy(Policy):

def __init__(self,policyN, policyO, cadd,age,smoke,medical,prem=0.0,policyD =" "):

Policy.__init__(policyN, policyO,cadd, prem=0.0,policyD =" ")

self.age=age

self.smoker=smoke

self.medical_status=medical

def setAge(self,a):#getter and setter methods

self.age=a

def setSmoker(self,a):

self.smoker=a

def setMedicalStatus(self,s):

self.medical_status=s

def getAge(self):

return self.age

def getSmoker(self):

return self.smoker

def getMedicalStatus(self):

return self.medical_status

def __str__(self):

s=Policy.__str__(self)

s +=" Age - "+str(self.getAge())+" Smoker - "+str(self.getSmoker())+" Medical status - "+str(self.getMedicalStatus())

return s

def CalculatePremium(self):

p=self.getPremium()

p+=100

if self.getSmoker():

p+=25

if self.getAge() >65:

p+=100

m=self.getMedicalStatus()

if m>=1 and m<=3:

p=p

elif m>=3 and m<=6:

p+=50

elif m>=7 and m<=10:

p+=100

self.setPremium(p)

if __name__ == '__main__':

life = LifePolicy("32115","Jane Doe","3422 Howard Ave. Dallas Mo",65,"True",5, 200, "20.08.2020")

print(life)

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions