1
+ package yangsooplus.ch04
2
+
3
+ import yangsooplus.ch02.Money
4
+ import java.time.Duration
5
+ import java.time.LocalDateTime
6
+
7
+ class Movie (
8
+ val title : String ,
9
+ val runningTime : Duration ,
10
+ private val fee : Money ,
11
+ val discountConditions : List <DiscountCondition >,
12
+
13
+ val movieType : MovieType ,
14
+ private val discountAmount : Money ,
15
+ private val discountPercent : Double
16
+ ) {
17
+ fun calculateAmountDiscountedFee (): Money {
18
+ return fee.minus(discountAmount)
19
+ }
20
+
21
+ fun calculatePercentDiscountedFee (): Money {
22
+ return fee.minus(fee.times(discountPercent))
23
+ }
24
+
25
+ fun calculateNoneDiscountedFee (): Money = fee
26
+
27
+ fun isDiscountable (whenScreened : LocalDateTime , sequence : Int ): Boolean {
28
+ discountConditions.forEach { condition ->
29
+ when (condition.type) {
30
+ DiscountConditionType .PERIOD -> {
31
+ if (condition.isDiscountable(whenScreened.dayOfWeek, whenScreened.toLocalTime()))
32
+ return true
33
+ }
34
+
35
+ DiscountConditionType .SEQUENCE -> {
36
+ if (condition.isDiscountable(sequence))
37
+ return true
38
+ }
39
+ }
40
+ }
41
+ return false
42
+ }
43
+
44
+ }
45
+
46
+ enum class MovieType {
47
+ AMOUNT_DISCOUNT , PERCENT_DISCOUNT , NONE_DISCOUNT
48
+ }
0 commit comments