Chapter 5 - Section 6
fun main(args: Array<String>) {
val item = ClothingItem("Shirt", "L", 19.99)
println(item)
item.price = 15.99
println(item)
val item2 = ClothingItem("M", 14.99)
println(item2)
println("Item type = ${item2.type}")
item2.price = 10.0
println("Item price = ${item2.price}")
val person = Person("Joe", "Smith")
println("That person is ${person.fullName}")
}
data class ClothingItem(private var _type: String?,
val size: String,
private var _price: Double) {
// init {
// _type = _type?.toUpperCase() ?: "UNKNOWN"
// }
var type: String? = _type
get() = field ?: "Unknown"
var price = _price
set(value) {
field = value * .9
}
constructor(size: String, price: Double) : this(null, size, price)
}
data class Person(private val firstName: String,
private val lastName: String) {
val fullName:String
get() = "$firstName $lastName"
}