diff --git a/kotlin/src/main/kotlin/com/baeldung/Item.kt b/kotlin/src/main/kotlin/com/baeldung/Item.kt index d145e894b3..6e552b3a42 100644 --- a/kotlin/src/main/kotlin/com/baeldung/Item.kt +++ b/kotlin/src/main/kotlin/com/baeldung/Item.kt @@ -1,3 +1,6 @@ package com.baeldung -data class Item(val id: String, val name: String = "unknown_name") \ No newline at end of file +open class Item(val id: String, val name: String = "unknown_name") + +class ItemWithCategory(id: String, name: String, val categoryId: String) : Item(id, name) + diff --git a/kotlin/src/main/kotlin/com/baeldung/ItemService.kt b/kotlin/src/main/kotlin/com/baeldung/ItemService.kt index 7597e2aca6..0b1c419ab4 100644 --- a/kotlin/src/main/kotlin/com/baeldung/ItemService.kt +++ b/kotlin/src/main/kotlin/com/baeldung/ItemService.kt @@ -5,6 +5,43 @@ import java.util.* class ItemService { fun findItemNameForId(id: String): Item? { val itemId = UUID.randomUUID().toString() - return Item(itemId, "name-$itemId"); + return Item(itemId, "name-$itemId") } +} + +class ItemManager(val categoryId: String, val dbConnection: String) { + var email = "" + + constructor(categoryId: String, dbConnection: String, email: String) : this(categoryId, dbConnection) { + this.email = email + } + + fun isFromSpecificCategory(catId: String): Boolean { + return categoryId == catId + } + + fun makeAnalyisOfCategory(catId: String): Unit { + val result = if (catId == "100") "Yes" else "No" + println(result) + + } +} + +fun main(args: Array) { + val numbers = arrayOf("first", "second", "third", "fourth") + + for (n in numbers) { + println(n) + } + + for (i in 0..9) { + println(i) + } + + val firstName = "Tom" + val secondName = "Mary" + println("Names: $firstName, $secondName") + + val itemManager = ItemManager("cat_id", "db://connection") + print("function result: ${itemManager.isFromSpecificCategory("1")}") } \ No newline at end of file