-
Notifications
You must be signed in to change notification settings - Fork 0
/
refactoring_8.py
103 lines (73 loc) · 2.39 KB
/
refactoring_8.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
class Movie:
CHILDRENS = 2
REGULAR = 0
NEW_RELEASE = 1
_title = None
_priceCode = None
def __init__(self, title, priceCode):
self._title = title
self._priceCode = priceCode
def getPriceCode(self):
return self._priceCode
def setPriceCode(self, arg):
self._priceCode = arg
def getTitle(self):
return self._title
class Rental:
_movie = None
_daysRented = None
def __init__(self, movie, daysRented):
self._movie = movie
self._daysRented = daysRented
def getDaysRented(self):
return self._daysRented
def getMovie(self):
return self._movie
def getCharge(self):
result = 0
priceCode = self.getMovie().getPriceCode()
if priceCode == Movie.REGULAR:
result += 2
if self.getDaysRented() > 2:
result += (self.getDaysRented() - 2) * 1.5
elif priceCode == Movie.NEW_RELEASE:
result += self.getDaysRented() * 3
elif priceCode == Movie.CHILDRENS:
result += 1.5
if self.getDaysRented() > 3:
result += (self.getDaysRented() - 3) * 1.5
return result
def getFrequentPoints(self):
if (self.getMovie().getPriceCode() == Movie.NEW_RELEASE) & (self.getDaysRented() > 1):
return 2
else:
return 1
class Customer:
_name = None
_rentals = []
def __init__(self, name):
self._name = name
def addRental(self, arg):
self._rentals.append(arg)
def getName(self):
return self._name
def getTotalCharge(self):
result = 0
for each in self._rentals:
result += each.getCharge()
return result
def getTotalFrequentRenterPoints(self):
result=0
for each in self._rentals:
result += each.getFrequentPoints()
return result
def statement(self):
result = "Rental Record for %s\n" % self.getName()
# determine amounts for each line
for each in self._rentals:
# show figures for this rental
result += "\t%s\t%s\n" % (each.getMovie().getTitle(), each.getCharge())
# add footer lines
result += "Amount owed is %s\n" % self.getTotalCharge()
result += "You earned %s frequent renter points" % self.getTotalFrequentRenterPoints()
return result