-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarRental.py
194 lines (153 loc) · 5.97 KB
/
CarRental.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import datetime
class CarRental:
__Subscribers = 0 # STATIC VARIABLE
__TotalBill = 0
def __init__(self, stock=0):
"""
Our constructor class that instantiates Car rental shop.
"""
self.stock = stock
def get_subscribers(): # @STATIC METHODS #Encapsulation
return CarRental.__Subscribers
def get_totalbill():
return CarRental.__TotalBill
def Rentedstock(self):
"""
Displays the Cars currently available for rent in the shop.
"""
c = 100 - self.stock
print("There are total {} Cars on rent.".format(c))
return c
def displaystock(self):
"""
Displays the Cars currently available for rent in the shop.
"""
print("We have currently {} Cars available to rent.".format(self.stock))
return self.stock
def rentCarOnHourlyBasis(self, n):
"""
Rents a Car on hourly basis to a customer.
"""
if n <= 0:
print("Number of Cars should be positive!")
return None
elif n > self.stock:
print("Sorry! We have currently {} Cars available to rent.".format(self.stock))
return None
else:
CarRental.__Subscribers = CarRental.__Subscribers + 1
now = datetime.datetime.now()
print("--> You have rented {} Car(s) on hourly basis on {}".format(n, now.strftime("%c")))
print("--> You will be charged $25 for each hour per Car.")
print("We hope that you enjoy our service.")
self.stock -= n
return now
def rentCarOnDailyBasis(self, n):
"""
Rents a Car on daily basis to a customer.
"""
if n <= 0:
print("Number of Cars should be positive!")
return None
elif n > self.stock:
print("Sorry! We have currently {} Cars available to rent.".format(self.stock))
return None
else:
CarRental.__Subscribers = CarRental.__Subscribers + 1
now = datetime.datetime.now()
print("--> You have rented {} Car(s) on daily basis on {}".format(n, now.strftime("%c")))
print("--> You will be charged $50 for each day per Car.")
print("We hope that you enjoy our service.")
self.stock -= n
return now
def rentCarOnWeeklyBasis(self, n):
"""
Rents a Car on weekly basis to a customer.
"""
if n <= 0:
print("Number of Cars should be positive!")
return None
elif n > self.stock:
print("Sorry! We have currently {} Cars available to rent.".format(self.stock))
return None
else:
CarRental.__Subscribers = CarRental.__Subscribers + 1
now = datetime.datetime.now()
print("--> You have rented {} Car(s) on weekly basis on {}".format(n, now.strftime("%c")))
print("--> You will be charged $100 for each week per Car.")
print("We hope that you enjoy our service.")
self.stock -= n
return now
def returnCar(self, request):
"""
1. Accept a rented Car from a customer
2. Replensihes the inventory
3. Return a bill
"""
rentalTime, rentalBasis, numOfCars = request
bill = 0
if rentalTime and rentalBasis and numOfCars:
self.stock += numOfCars
now = datetime.datetime.now()
print("RentalTime is:",rentalTime)
rentalPeriod = now - rentalTime
# hourly bill calculation
if rentalBasis == 1:
bill = round(rentalPeriod.seconds / 3600) * 5 * numOfCars
# daily bill calculation
elif rentalBasis == 2:
bill = round(rentalPeriod.days) * 20 * numOfCars
# weekly bill calculation
elif rentalBasis == 3:
bill = round(rentalPeriod.days / 7) * 60 * numOfCars
if (3 <= numOfCars <= 5):
print("You are eligible for Family rental promotion of 30% discount")
bill = bill * 0.7
CarRental.__TotalBill = CarRental.__TotalBill + bill
print("Thanks for returning your Car. Hope you enjoyed our service!")
print("""
Your Bill Receipt is:
"1.Selected RentalBasis:{}
"2.Booking Time:{}
"3.Returning Time:{}
"4.No Of Cars:{}
"5.Rental Period:{}""".format(rentalBasis, rentalTime, now, numOfCars, rentalPeriod)
)
print("That would be ${}".format(bill))
return bill
else:
print("Are you sure you rented a Car with us?")
return None
class Customer:
def __init__(self):
"""
Our constructor method which instantiates various customer objects.
"""
self.Cars = 0
self.rentalBasis = 0
self.rentalTime = 0
self.bill = 0
def requestCar(self):
"""
Takes a request from the customer for the number of Cars.
"""
Cars = input("How many Cars would you like to rent?")
try:
Cars = int(Cars)
except ValueError:
print("That's not a positive integer!")
return -1
if Cars < 1:
print("Invalid input. Number of Cars should be greater than zero!")
return -1
else:
self.Cars = Cars
return self.Cars
def returnCar(self):
"""
Allows customers to return their Cars to the rental shop.
"""
if self.rentalBasis and self.rentalTime and self.Cars:
return self.rentalTime, self.rentalBasis, self.Cars
else:
return 0, 0, 0