July 2018
Intermediate to advanced
400 pages
12h 14m
English
Like lists and sets, maps are created using functions: mapOf and mutableMapOf. In Tavern.kt, create a map representing the amount of gold each patron’s purse contains. (We will explain the argument syntax shortly.)
Listing 11.1 Creating a read-only map (Tavern.kt)
...
var uniquePatrons = mutableSetOf<String>()
val menuList = File("data/tavern-menu-items.txt")
.readText()
.split("\n")
val patronGold = mapOf("Eli" to 10.5, "Mordoc" to 8.0, "Sophie" to 5.5)
fun main(args: Array<String>) {
...
println(uniquePatrons)
var orderCount = 0
while (orderCount <= 9) {
placeOrder(uniquePatrons.shuffled().first(),
menuList.shuffled().first())
orderCount++
}
println(patronGold)
}
...
While the keys in a map must all be ...
Read now
Unlock full access