Amount owed is ${usd(data.totalAmount/100)}
\n" result += s"You earned ${data.totalVolumeCredits} credits
\n" result Status: Separated into Two Files (and Phases)Amount owed is $1,730.00
|You earned 47 credits
|""".stripMargin ) Let’s add an assertion test for htmlStatement. Status: Separated into Two Files (and Phases) @philip_schwarzAmount owed is ${usd(data.totalAmount/100)}
\n" result += s"You earned ${data.totalVolumeCredits} credits
\n" result def usd(aNumber: Int): String = val formatter = NumberFormat.getCurrencyInstance(Locale.US) formatter.setCurrency(Currency.getInstance(Locale.US)) formatter.format(aNumber) Refactored Program Statement.scalaAmount owed is ${usd(data.totalAmount/100)}
\n" result += s"You earned ${data.totalVolumeCredits} credits
\n" result def renderPlainText(data: StatementData): String = var result = s"Statement for ${data.customer}\n" for (perf <- data.performances) result += s" ${perf.play.name}: ${usd(perf.amount/100)} (${perf.audience} seats)\n" result += s"Amount owed is ${usd(data.totalAmount/100)}\n" result += s"You earned ${data.totalVolumeCredits} credits\n" result def renderHtml(data: StatementData): String = s"""|Amount owed is ${usd(data.totalAmount/100)}
|You earned ${data.totalVolumeCredits} credits
|""".stripMargin def renderPlainText(data: StatementData): String = s"Statement for ${data.customer}\n" + ( for perf <- data.performances yield s" ${perf.play.name}: ${usd(perf.amount/100)} (${perf.audience} seats)\n" ).mkString + s"""|Amount owed is ${usd(data.totalAmount/100)} |You earned ${data.totalVolumeCredits} credits |""".stripMargin Next, let’s get rid of the mutability in the rendering logic.