-
Notifications
You must be signed in to change notification settings - Fork 0
/
refactoring_2.py
92 lines (67 loc) · 2.3 KB
/
refactoring_2.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
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
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 amountFor(self, aRental):
result = 0
priceCode = aRental.getMovie().getPriceCode()
if priceCode == Movie.REGULAR:
result += 2
if aRental.getDaysRented() > 2:
result += (aRental.getDaysRented() - 2) * 1.5
elif priceCode == Movie.NEW_RELEASE:
result += aRental.getDaysRented() * 3
elif priceCode == Movie.CHILDRENS:
result += 1.5
if aRental.getDaysRented() > 3:
result += (aRental.getDaysRented() - 3) * 1.5
return result
def statement(self):
totalAmount = 0
frequentRenterPoints = 0
result = "Rental Record for %s\n" % self.getName()
# determine amounts for each line
for each in self._rentals:
thisAmount = self.amountFor(each)
# add frequent renter points
frequentRenterPoints += 1
# add bonus for a two day new release rental
if (each.getMovie().getPriceCode() == Movie.NEW_RELEASE) & (each.getDaysRented() > 1):
frequentRenterPoints += 1
# show figures for this rental
result += "\t%s\t%s\n" % (each.getMovie().getTitle(), thisAmount)
totalAmount += thisAmount
# add footer lines
result += "Amount owed is %s\n" % totalAmount
result += "You earned %s frequent renter points" % frequentRenterPoints
return result