Created
September 12, 2018 13:27
-
-
Save Serchinastico/4dfc212c59824ebf8ce2d016bf50cf34 to your computer and use it in GitHub Desktop.
Classes exercise in kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Product( | |
val id: String | |
) { | |
abstract val name: String | |
abstract var priceInEuros: Int | |
var priceInDollars: Int | |
get() = (priceInEuros * 1.06).toInt() | |
set(value) { | |
priceInEuros = (value / 1.06).toInt() | |
} | |
val description: String | |
get() = "[$name] - $id" | |
} | |
class TShirt( | |
id: String, | |
override var priceInEuros: Int | |
) : Product(id) { | |
override val name: String = "T-shirt" | |
} | |
class Jeans( | |
id: String, | |
override var priceInEuros: Int | |
) : Product(id) { | |
override val name: String = "Jeans" | |
} | |
object Cart { | |
val products = arrayOf( | |
TShirt("tshirt#01", 19), | |
TShirt("tshirt#02", 15), | |
Jeans("jeans#01", 30), | |
Jeans("jeans#02", 40) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment