File tree Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,21 @@ class Rental
1717 def initialize ( movie , days_rented )
1818 @movie , @days_rented = movie , days_rented
1919 end
20+
21+ def charge
22+ result = 0
23+ case movie . price_code
24+ when Movie ::REGULAR
25+ result += 2
26+ result += ( days_rented - 2 ) * 1.5 if days_rented > 2
27+ when Movie ::NEW_RELEASE
28+ result += days_rented * 3
29+ when Movie ::CHILDRENS
30+ result += 1.5
31+ result += ( days_rented - 3 ) * 1.5 if days_rented > 3
32+ end
33+ result
34+ end
2035end
2136
2237
@@ -55,18 +70,7 @@ def statement
5570 end
5671
5772 def amount_for ( rental )
58- result = 0
59- case rental . movie . price_code
60- when Movie ::REGULAR
61- result += 2
62- result += ( rental . days_rented - 2 ) * 1.5 if rental . days_rented > 2
63- when Movie ::NEW_RELEASE
64- result += rental . days_rented * 3
65- when Movie ::CHILDRENS
66- result += 1.5
67- result += ( rental . days_rented - 3 ) * 1.5 if rental . days_rented > 3
68- end
69- result
73+ rental . charge
7074 end
7175end
7276
You can’t perform that action at this time.
0 commit comments