Skip to content

Commit 58e6faf

Browse files
LysounCLOVIS-AI
authored andcommitted
tp3 step 2 solution
1 parent ead4ce1 commit 58e6faf

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package fmt.kotlin.fundamentals
2+
3+
class Cellar private constructor(
4+
ownerName: String,
5+
private var wineBarrels: List<WineBarrel>,
6+
) {
7+
constructor(ownerName: String) : this(ownerName, listOf())
8+
9+
val totalWineCapacityInLiters: Int
10+
get() {
11+
var totalCapacity = 0
12+
13+
for (wineBarrel in wineBarrels) {
14+
totalCapacity += wineBarrel.capacityInLiters
15+
}
16+
17+
return totalCapacity
18+
}
19+
20+
var cellarName = "Cave de " + ownerName
21+
set(ownerName) {
22+
field = "Cave de " + ownerName
23+
}
24+
25+
fun addBarrels(wineBarrels: List<WineBarrel>) {
26+
this.wineBarrels = this.wineBarrels.plus(wineBarrels)
27+
}
28+
29+
fun age(monthsNumber: Int) {
30+
for (wineBarrel in wineBarrels) {
31+
wineBarrel.age(monthsNumber)
32+
}
33+
}
34+
}

tp3/src/main/kotlin/fmt/kotlin/fundamentals/WineBarrel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ class WineBarrel private constructor(
44
val capacityInLiters: Int = 225,
55
private var wineAgeInMonths: Int
66
) {
7+
fun age(monthsNumber: Int) {
8+
wineAgeInMonths += monthsNumber
9+
}
10+
711
constructor(capacityInLiters: Int = 225) : this(capacityInLiters, 0)
812

913
constructor(capacityInLiters: Int = 225, wineBarrel: WineBarrel) : this(

0 commit comments

Comments
 (0)