Skip to content

Instantly share code, notes, and snippets.

@a-dminator
Created February 24, 2019 16:37
Show Gist options
  • Save a-dminator/3e1c8a6d64485620ebfa0ae60b1cd62d to your computer and use it in GitHub Desktop.
Save a-dminator/3e1c8a6d64485620ebfa0ae60b1cd62d to your computer and use it in GitHub Desktop.
abstract class Books(
val author: String,
val name: String,
val special: String,
val price: Double
) {
abstract fun printDescription()
}
abstract class Fiction(
author: String,
name: String,
price: Double,
val genre: String
) : Books(
author,
name,
"Художественная литература",
price
)
abstract class Applied(
author: String,
name: String,
price: Double,
val genre: String
) : Books(
author,
name,
"Прикладная литература",
price
)
abstract class Study(
author: String,
name: String,
price: Double,
val subject: String
) : Books(
author,
name,
"Учебная литература",
price
)
class Novel(
author: String,
name: String,
price: Double
) : Fiction(
author,
name,
price,
"Роман"
) {
override fun printDescription() =
println("$special, '$name' ($author), Жанр: $genre, Цена: $price $")
}
class Psychology(
author: String,
name: String,
price: Double
) : Applied(
author,
name,
price,
"Психология"
) {
override fun printDescription() =
println("$special, '$name' ($author), Жанр: $genre, Цена: $price $")
}
class Mathematics(
author: String,
name: String,
price: Double
) : Study(
author,
name,
price,
"Математика"
) {
override fun printDescription() =
println("$special, '$name' ($author), Предмет: $subject, Цена: $price $")
}
fun main() {
val greenMile = Novel(
author = "Стивенг Кинг",
name = "Зеленая Миля",
price = 12.0
)
val howToWinFriendsAndInfluencePeople = Psychology(
author = "Дейл Карнеги",
name = "Как завоёвывать друзей и оказывать влияние на людей",
price = 3.99
)
val geometry10_11 = Mathematics(
author = "Атанасян",
name = "Геометрия для 10-11 классов",
price = 10.0
)
val books = listOf(greenMile, howToWinFriendsAndInfluencePeople, geometry10_11)
books.forEach { book ->
book.printDescription()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment