Class Property
Class Property
a. Create a Property class with an address, 6 digit postal code number, tenure, completion year,
property type, area, commission rate and valuation. Add appropriate constructors and member
functions to initialize, access, and manipulate the data members. Commission rate is default to 1%.
class Property:
def __init__(self, address, postal_code, tenure, completion_year,
property_type, area, valuation, commission_rate=1.0):
def __str__(self):
b. Design the class CommercialProperty, that extends from the class Property, with an additional data
member to store the commercial property type (for office, flatted factory, factory). Add appropriate
constructors and member functions to initialize, access, and manipulate the data members.
class CommercialProperty(Property):
def __init__(self, address, postal_code, tenure, completion_year,
property_type, area, valuation, commercial_type, commission_rate=1.0):
"""
Initializes a CommercialProperty object by extending the Property
class.
Args:
commercial_type (str): The commercial property type (e.g.,
office, flatted factory, factory).
"""
super().__init__(address, postal_code, tenure, completion_year,
property_type, area, valuation, commission_rate)
self.commercial_type = commercial_type
def __str__(self):
"""
Returns a string representation of the CommercialProperty object.
"""
return super().__str__() + f", commercial type:
{self.commercial_type}"
class PropertyAgent:
def __init__(self, company, agent_registration_number, start_year):
self.company = company
self.agent_registration_number = agent_registration_number
self.start_year = start_year
self.properties_not_sold = [] # List of properties not yet sold
self.properties_sold = [] # List of properties sold
self.commission_rate = 0.7 # Default commission sharing rate (70%)
c. Create a PropertyAgent class that holds 2 list of properties. One list of properties held are the ones
that the property agent has not sold, while another list of properties holds the properties sold by the
agent during the year. The PropertyAgent would also have data members commission sharing rate
default to 70%, the company he worked for, his/her agent registration number and the year the agent
began working.
# class PropertyAgent:
# def __init__(self, company, agent_registration_number, start_year):
# self.company = company
# self.agent_registration_number = agent_registration_number
# self.start_year = start_year
# self.properties_not_sold = [] # List of properties not yet sold
# self.properties_sold = [] # List of properties sold
# self.commission_rate = 0.7 # Default commission sharing rate
(70%)
#
# def add_property(self, property_info, sold=False):
# """
# Add a property to the agent's list (either sold or unsold).
# :param property_info: Information about the property (e.g.,
address, price, etc.)
# :param sold: True if the property is sold, False if not sold
(default is False)
# """
# if sold:
# self.properties_sold.append(property_info)
# else:
# self.properties_not_sold.append(property_info)
#
# def calculate_commission(self, sale_price):
# """
# Calculate the agent's commission based on the sale price and
commission rate.
# :param sale_price: Price at which the property was sold
# :return: Commission amount
# """
# return sale_price * self.commission_rate
class PropertyAgent:
def __init__(self, company, agent_registration_number, start_year):
self.company = company
self.agent_registration_number = agent_registration_number
self.start_year = start_year
self.properties_sold = [] # List of sold properties
self.commission_rate = 0.03 # Default commission rate (3%)
d. Design the class PropertyAgencyDirector that extends from the PropertyAgent class with an
additional data member default to 5% to a maximum of 15% of the commission earned by the agent
and a list of agents working under him/her. The commission sharing rate is now default to 75% and is
at maximum 90% of commissions earned.
class PropertyAgencyDirector(PropertyAgent):
def __init__(self, company, agent_registration_number, start_year):
super().__init__(company, agent_registration_number, start_year)
self.additional_commission_rate = 0.05 # Default additional
commission rate (5%)
self.max_additional_commission_rate = 0.15 # Maximum additional
commission rate (15%)
self.agents_working_under = [] # List of agents working under the
director
self.commission_sharing_rate = 0.75 # Default commission sharing
rate (75%)
self.max_commission_sharing_rate = 0.90 # Maximum commission
sharing rate (90%)
e. Design the class CommissionSlip to calculate and display an agent’s commission earned for the
year based on the properties sold (based on the commission rate) multiplied by the commission
sharing rate. Eg. If the agent sold a property worth $1 million with commission rate of 1% and his
sharing rate is 70%, the commission earned will be $1,000,000 * 0.01 * 0.7 = $7,000. If the agent is a
Property Agent Director, then he/she will have overriding commission of his/her agents at the rate.
The commission slip shall therefore show the breakdown of commissions earned per property, the
commission sharing for each property, the total commission earned for the property agent. If the agent
is a directory, there will be the breakdown of the overriding income for each agent and the total
overriding income earned as well as the total income earned.
class CommissionSlip:
def __init__(self, agent_or_director):
self.agent_or_director = agent_or_director
self.sales = []
def display_commission_slip(self):
print(f"Commission Slip for
{self.agent_or_director.agent_registration_number}")
print("=" * 30)
total_commission = 0
for property, sale_price in self.sales:
commission = sale_price * 0.03 # Assume 3% commission rate
total_commission += commission
print(f"Property: {property.address}, Sale Price: {sale_price},
Commission: {commission}")
print(f"Total Commission: {total_commission}")
print("=" * 30)
def main():
directors = []
agents = []
properties = []
for i in range(num_directors):
print(f"\nEntering details for director {i + 1}:")
company = input("Enter the director's company: ")
registration_number = input("Enter the director's registration
number: ")
while True:
try:
start_year = input("Enter the director's start year: ")
if len(start_year) == 4 and start_year.isdigit():
start_year = int(start_year)
break
else:
raise ValueError
except ValueError:
print("Invalid input. Please enter a valid 4-digit
year.")
directors.append(PropertyAgencyDirector(company,
registration_number, start_year))
print("Directors created successfully!\n")
def create_agents():
while True:
try:
num_agents = int(input("Enter the number of agents to
create: "))
break
except ValueError:
print("Invalid input. Please enter a valid number.")
for i in range(num_agents):
print(f"\nEntering details for agent {i + 1}:")
company = input("Enter the agent's company: ")
registration_number = input("Enter the agent's registration
number: ")
while True:
try:
start_year = input("Enter the agent's start year: ")
if len(start_year) == 4 and start_year.isdigit():
start_year = int(start_year)
break
else:
raise ValueError
except ValueError:
print("Invalid input. Please enter a valid 4-digit
year.")
agents.append(PropertyAgent(company, registration_number,
start_year))
print("Agents created successfully!\n")
def create_properties():
while True:
try:
num_properties = int(input("Enter the number of properties
to create: "))
break
except ValueError:
print("Invalid input. Please enter a valid number.")
for i in range(num_properties):
print(f"\nEntering details for property {i + 1}:")
while True:
address = input("Enter the property address: ")
if address.strip():
break
else:
print("Invalid input. Address cannot be empty.")
while True:
try:
postal_code = input("Enter the property postal code: ")
if len(postal_code) == 6 and postal_code.isdigit():
postal_code = int(postal_code)
break
else:
raise ValueError
except ValueError:
print("Invalid input. Please enter a valid 6-digit
postal code.")
while True:
try:
valuation = float(input("Enter the property valuation:
"))
break
except ValueError:
print("Invalid input. Please enter a valid valuation.")
def assign_properties_to_agents():
for agent in agents:
while True:
try:
num_unsold = int(input(
f"Enter the number of unsold properties to assign
to agent {agent.agent_registration_number}: "))
if 0 <= num_unsold <= len(properties):
break
else:
raise ValueError
except ValueError:
print("Invalid input. Please enter a valid number
within the range.")
for _ in range(num_unsold):
while True:
try:
property_index = int(
input(f"Enter the property index (0 to
{len(properties) - 1}) to assign: "))
if 0 <= property_index < len(properties):
break
else:
print(f"Invalid index. Please enter a number
between 0 and {len(properties) - 1}.")
except ValueError:
print("Invalid input. Please enter a valid
number.")
agent.add_property(properties[property_index], sold=False)
while True:
try:
num_sold = int(input(
f"Enter the number of sold properties to assign to
agent {agent.agent_registration_number}: "))
if 0 <= num_sold <= len(properties):
break
else:
raise ValueError
except ValueError:
print("Invalid input. Please enter a valid number
within the range.")
for _ in range(num_sold):
while True:
try:
property_index = int(
input(f"Enter the property index (0 to
{len(properties) - 1}) to assign: "))
if 0 <= property_index < len(properties):
break
else:
print(f"Invalid index. Please enter a number
between 0 and {len(properties) - 1}.")
except ValueError:
print("Invalid input. Please enter a valid
number.")
agent.add_property(properties[property_index], sold=True)
def assign_agents_to_directors():
for director in directors:
while True:
try:
num_agents = int(input(
f"Enter the number of agents to assign to director
{director.agent_registration_number}: "))
if 0 <= num_agents <= len(agents):
break
else:
raise ValueError
except ValueError:
print("Invalid input. Please enter a valid number
within the range.")
for _ in range(num_agents):
while True:
try:
agent_index = int(input(f"Enter the agent index (0
to {len(agents) - 1}) to assign: "))
if 0 <= agent_index < len(agents):
break
else:
print(f"Invalid index. Please enter a number
between 0 and {len(agents) - 1}.")
except ValueError:
print("Invalid input. Please enter a valid
number.")
director.add_agent(agents[agent_index])
create_directors()
create_agents()
create_properties()
assign_properties_to_agents()
assign_agents_to_directors()
if __name__ == "__main__":
main()