July 2018
Intermediate to advanced
400 pages
12h 14m
English
Take another look at the menuData string for the tavern:
"shandy,Dragon's Breath,5.91"
Madrigal needs to pay 5.91 gold for the Dragon’s Breath, so playerGold should decrease by 5.91 when the drink is ordered.
Numeric values with decimal places are represented with the Float or Double type. Update Tavern.kt so that a double with the value for the item is passed to the performPurchase function:
Listing 8.2 Passing the price information (Tavern.kt)
const val TAVERN_NAME = "Taernyl's Folly"
...
fun performPurchase(price: Double) {
displayBalance()
println("Purchasing item for $price") } ... private fun placeOrder(menuData: String) { ... val (type, name, price) = menuData.split(',') val message = "Madrigal ...Read now
Unlock full access