@@ -8,18 +8,24 @@ data class StatementData(
88 var totalVolumeCredits: Int = 0
99}
1010
11- class EnrichedPerformance (
12- val playID : String , val audience : Int , val play : Play
13- ) {
11+ class EnrichedPerformance () {
12+ var playID: String = " "
13+ var audience : Int = 0
1414 var amount: Int = 0
1515 var volumeCredits: Int = 0
16+ var play: Play ? = null
1617 var performanceCalculator: PerformanceCalculator ? = null
18+
19+ constructor (aPerformance: Performance ) : this () {
20+ this .playID = aPerformance.playID
21+ this .audience = aPerformance.audience
22+ }
1723}
1824
1925class PerformanceCalculator {
20- var aPerformance: EnrichedPerformance
26+ var aPerformance: Performance
2127
22- constructor (aPerformance: EnrichedPerformance ) {
28+ constructor (aPerformance: Performance ) {
2329 this .aPerformance = aPerformance
2430 }
2531}
@@ -31,7 +37,7 @@ internal fun createStatementData(plays: Plays, invoice: Invoice): StatementData
3137
3238 fun amountFor (aPerformance : EnrichedPerformance ): Int {
3339 var result = 0
34- when (aPerformance.play.type) {
40+ when (aPerformance.play? .type) {
3541 " tragedy" -> {
3642 result = 40000
3743 if (aPerformance.audience > 30 ) {
@@ -48,7 +54,7 @@ internal fun createStatementData(plays: Plays, invoice: Invoice): StatementData
4854 }
4955
5056 else -> {
51- throw Error (" 알 수 없는 장르: ${aPerformance.play.type} " )
57+ throw Error (" 알 수 없는 장르: ${aPerformance.play? .type} " )
5258 }
5359 }
5460
@@ -57,7 +63,7 @@ internal fun createStatementData(plays: Plays, invoice: Invoice): StatementData
5763
5864 fun volumeCreditsFor (aPerformance : EnrichedPerformance ): Int {
5965 var result = maxOf(aPerformance.audience - 30 , 0 )
60- if (aPerformance.play.type == " comedy" ) result + = aPerformance.audience / 5
66+ if (aPerformance.play? .type == " comedy" ) result + = aPerformance.audience / 5
6167 return result
6268 }
6369
@@ -70,16 +76,16 @@ internal fun createStatementData(plays: Plays, invoice: Invoice): StatementData
7076 }
7177
7278 fun enrichPerformance (aPerformance : Performance ): EnrichedPerformance {
73- val result = EnrichedPerformance (
74- aPerformance.playID, aPerformance.audience, playFor (aPerformance)
75- )
79+ val calculator = PerformanceCalculator (aPerformance)
80+ val result = EnrichedPerformance (aPerformance)
81+ result.play = playFor(aPerformance )
7682 result.amount = amountFor(result)
7783 result.volumeCredits = volumeCreditsFor(result)
78- result.performanceCalculator = PerformanceCalculator (result)
7984 return result
8085 }
8186
82- val statementData = StatementData (invoice.customer, invoice.performances.map { enrichPerformance(it) }).apply {
87+ val statementData = StatementData (
88+ invoice.customer, invoice.performances.map { enrichPerformance(it) }).apply {
8389 totalAmount = totalAmount(this )
8490 totalVolumeCredits = totalVolumeCredits(this )
8591 }
0 commit comments