-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.py
71 lines (62 loc) · 2.74 KB
/
agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from houserental import HouseRental
from housepurchase import HousePurchase
from apartmentrental import ApartmentRental
from apartmentpurchase import ApartmentPurchase
from functions import get_valid_input
class Agent:
class_dict = {('house', 'rental'): HouseRental, ('house', 'purchase'): HousePurchase,
('apartment', 'rental'): ApartmentRental, ('apartment', 'purchase'): ApartmentPurchase}
def __init__(self):
self.property_list = []
def add_property(self):
property_type = get_valid_input('What type of property? ', ('house', 'apartment')).lower()
payment_type = get_valid_input('What payment type? ', ('purchase', 'rental')).lower()
item = None
if property_type == 'house' and payment_type == 'purchase':
item = HousePurchase()
elif property_type == 'house' and payment_type == 'rental':
item = HouseRental()
if property_type == 'apartment' and payment_type == 'purchase':
item = ApartmentPurchase()
elif property_type == 'apartment' and payment_type == 'rental':
item = ApartmentRental()
self.property_list.append(item)
def show_all_properties(self):
count = 1
for i in self.property_list:
print(f'{count}) ', end='')
if type(i) == HousePurchase:
print('HousePurchase:', i)
elif type(i) == HouseRental:
print('HouseRental:', i)
elif type(i) == ApartmentPurchase:
print('ApartmentPurchase:', i)
else:
print('ApartmentRental:', i)
count += 1
if count == 1:
print("No property has been added yet!")
def show_match_property(self):
property_type = get_valid_input("Property Type: ", ('house', 'apartment'))
payment_type = get_valid_input("Payment Type: ", ('purchase', 'rental'))
obj_property_class = Agent.class_dict[(property_type, payment_type)]
count = 1
for i in self.property_list:
if type(i) == obj_property_class:
print(f"{count}) {i}")
count += 1
if count == 1:
print("No specified property is available.")
def modify_property(self):
property_no = int(input("Property No: "))
if 1 > property_no or property_no > len(self.property_list):
print("Invalid property number")
else:
self.property_list[property_no-1].set_values_type_payment()
if __name__ == "__main__":
pass
# a1 = Agent()
# a1.add_property()
# a1.add_property()
# if type(a1.property_list[0]) == HousePurchase:
# print('Yes boy! its working')