Skip to content

Commit 8e89c93

Browse files
author
Tomasz Lelek
committed
BAEL-19 introduce basic concstruct
1 parent b167fc5 commit 8e89c93

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
package com.baeldung
22

3-
data class Item(val id: String, val name: String = "unknown_name")
3+
open class Item(val id: String, val name: String = "unknown_name")
4+
5+
class ItemWithCategory(id: String, name: String, val categoryId: String) : Item(id, name)
6+

‎kotlin/src/main/kotlin/com/baeldung/ItemService.kt‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,43 @@ import java.util.*
55
class ItemService {
66
fun findItemNameForId(id: String): Item? {
77
val itemId = UUID.randomUUID().toString()
8-
return Item(itemId, "name-$itemId");
8+
return Item(itemId, "name-$itemId")
99
}
10+
}
11+
12+
class ItemManager(val categoryId: String, val dbConnection: String) {
13+
var email = ""
14+
15+
constructor(categoryId: String, dbConnection: String, email: String) : this(categoryId, dbConnection) {
16+
this.email = email
17+
}
18+
19+
fun isFromSpecificCategory(catId: String): Boolean {
20+
return categoryId == catId
21+
}
22+
23+
fun makeAnalyisOfCategory(catId: String): Unit {
24+
val result = if (catId == "100") "Yes" else "No"
25+
println(result)
26+
27+
}
28+
}
29+
30+
fun main(args: Array<String>) {
31+
val numbers = arrayOf("first", "second", "third", "fourth")
32+
33+
for (n in numbers) {
34+
println(n)
35+
}
36+
37+
for (i in 0..9) {
38+
println(i)
39+
}
40+
41+
val firstName = "Tom"
42+
val secondName = "Mary"
43+
println("Names: $firstName, $secondName")
44+
45+
val itemManager = ItemManager("cat_id", "db://connection")
46+
print("function result: ${itemManager.isFromSpecificCategory("1")}")
1047
}

0 commit comments

Comments
 (0)