July 2018
Intermediate to advanced
400 pages
12h 14m
English
Now that the player’s remaining balance has been calculated, all that is left to do is to convert the remaining balance back to gold and silver amounts.
Update the performPurchase function to convert the player’s total purse value to gold and silver. (Make sure to add the import kotlin.math.roundToInt statement at the top of the file.)
Listing 8.6 Converting to silver and gold (Tavern.kt)
import kotlin.math.roundToInt const val TAVERN_NAME = "Taernyl's Folly" ... fun performPurchase(price: Double) { displayBalance() val totalPurse = playerGold + (playerSilver / 100.0) println("Total purse: $totalPurse") println("Purchasing item for $price") val remainingBalance = totalPurse - price println("Remaining ...Read now
Unlock full access