Skip to content

Instantly share code, notes, and snippets.

@Serchinastico
Created September 12, 2018 13:27
Show Gist options
  • Save Serchinastico/4dfc212c59824ebf8ce2d016bf50cf34 to your computer and use it in GitHub Desktop.
Save Serchinastico/4dfc212c59824ebf8ce2d016bf50cf34 to your computer and use it in GitHub Desktop.
Classes exercise in kotlin
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