Skip to content

Commit 84748cb

Browse files
committed
ch01: 원본 amountFor 함수가 PerformanceCalculator를 이용하도록 위임
1 parent fca97b0 commit 84748cb

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

src/main/kotlin/chapter01/CreateStatementData.kt

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,8 @@ internal fun createStatementData(plays: Plays, invoice: Invoice): StatementData
6363
return plays[aPerformance.playID]!!
6464
}
6565

66-
fun amountFor(aPerformance: EnrichedPerformance): Int {
67-
var result = 0
68-
when (aPerformance.play?.type) {
69-
"tragedy" -> {
70-
result = 40000
71-
if (aPerformance.audience > 30) {
72-
result += 1000 * (aPerformance.audience - 30)
73-
}
74-
}
75-
76-
"comedy" -> {
77-
result = 30000
78-
if (aPerformance.audience > 20) {
79-
result += 10000 + 500 * (aPerformance.audience - 20)
80-
}
81-
result += 300 * aPerformance.audience
82-
}
83-
84-
else -> {
85-
throw Error("알 수 없는 장르: ${aPerformance.play?.type}")
86-
}
87-
}
88-
89-
return result
66+
fun amountFor(aPerformance: Performance): Int {
67+
return PerformanceCalculator(aPerformance, playFor(aPerformance)).amount
9068
}
9169

9270
fun volumeCreditsFor(aPerformance: EnrichedPerformance): Int {
@@ -107,7 +85,7 @@ internal fun createStatementData(plays: Plays, invoice: Invoice): StatementData
10785
val calculator = PerformanceCalculator(aPerformance, playFor(aPerformance))
10886
val result = EnrichedPerformance(aPerformance)
10987
result.play = calculator.play
110-
result.amount = amountFor(result)
88+
result.amount = amountFor(aPerformance)
11189
result.volumeCredits = volumeCreditsFor(result)
11290
return result
11391
}

0 commit comments

Comments
 (0)