-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrent.py
196 lines (136 loc) · 5.09 KB
/
rent.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
195
196
import datetime
#parent class
class VehicleRent():
def __init__(self, stock):
self.stock = stock
self.now = 0
def displayStock(self):
print("{} vehicle available to rent".format(self.stock))
return self.stock
def rentHourly(self, n):
if n <= 0:
print("Number should be positive")
return None
elif n > self.stock:
print("Sorry {} vehicle available to rent".format(self.stock))
return None
else:
self.now = datetime.datetime.now()
print("Rented a {} vehicle for hourly at {} hours".format(n,self.now.hour))
self.stock -= n
return self.now
def rentDaily(self, n):
if n <= 0:
print("Number should be positive")
return None
elif n > self.stock:
print("Sorry {} vehicle available to rent".format(self.stock))
return None
else:
self.now = datetime.datetime.now()
print("Rented a {} vehicle for daily at {} hours".format(n,self.now.hour))
self.stock -= n
return self.now
def returnVehicle(self, request, brand):
car_h_price = 10
car_d_price = car_h_price*8/10*24
bike_h_price =5
bike_d_price = bike_h_price*7/10*24
rentalTime, rentalBasis, numOfVehicle = request
bill = 0
if brand == "car":
if rentalTime and rentalBasis and numOfVehicle:
self.stock += numOfVehicle
now = datetime.datetime.now()
rentalPeriod = now - rentalTime
if rentalBasis == 1: #hourly
bill = rentalPeriod.seconds/3600*car_h_price*numOfVehicle
elif rentalBasis == 2: #daily
bill = rentalPeriod.seconds/(3600*24)*car_d_price*numOfVehicle
if ( 2 <= numOfVehicle):
print("You have extra %20 discount")
bill = bill*0.8
print("Thank you for returning your car")
print("Price : $ {}".format(bill))
return bill
elif brand == "bike":
if rentalTime and rentalBasis and numOfVehicle:
self.stock += numOfVehicle
now = datetime.datetime.now()
rentalPeriod = now - rentalTime
if rentalBasis ==1: #hourly
bill = rentalPeriod.seconds/3600*bike_h_price*numOfVehicle
elif rentalBasis == 2: #daily
bill = rentalPeriod.seconds/(3600*24)*bike_d_price*numOfVehicle
if ( 4 <= numOfVehicle):
print("You have extra %20 discount")
bill = bill*0.8
print("Thank you for returning your bike")
print("Price : $ {}".format(bill))
return bill
else:
print("You do not rent a vehicle ")
return None
#child class 1
class CarRent(VehicleRent):
global discount_rate
discount_rate = 15
def __init__(self,stock):
super().__init__(stock)
def discount(self, b):
bill = b - (b*discount_rate)/100
return bill
#child class 2
class BikeRent(VehicleRent):
def __init__(self, stock):
super().__init__(stock)
class Customer:
def __init__(self):
self.bikes = 0
self.rentalBasis_b = 0
self.rentalTime_b = 0
self.cars = 0
self.rentalBasis_c = 0
self.rentalTime_c = 0
def requestVehicle(self, brand):
if brand == "bike":
bikes = input("How many bikes would you like to rent? ")
try:
bikes = int(bikes)
except ValueError:
print("Number should be number")
return -1
if bikes < 1:
print("Number of Bikes should be greater than zero")
return -1
else:
self.bikes = bikes
return self.bikes
elif brand == "car":
cars = input("How many cars would you like to rent? ")
try:
cars = int(cars)
except ValueError:
print("Number should be number")
return -1
if cars < 1:
print("Number of Cars should be greater than zero")
return -1
else:
self.cars = cars
return self.cars
else:
print("Request vehicle eror")
def returnVehicle(self, brand):
if brand == "bike":
if self.rentalTime_b and self.rentalBasis_b and self.bikes:
return self.rentalTime_b, self.rentalBasis_b, self.bikes
else:
return 0,0,0
elif brand == "car":
if self.rentalTime_c and self.rentalBasis_c and self.cars:
return self.rentalTime_c, self.rentalBasis_c, self.cars
else:
return 0,0,0
else:
print("Return vehicle Error")