Skip to content

Commit 1c4f6ff

Browse files
LysounCLOVIS-AI
authored andcommitted
tp3 step 3 solution
1 parent 9461a1c commit 1c4f6ff

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,20 @@ class Cellar private constructor(
3131
wineBarrel.age(monthsNumber)
3232
}
3333
}
34+
35+
fun description(): String {
36+
var description = """
37+
Nom de la cave : $cellarName
38+
Nombre de barriques: ${wineBarrels.size}
39+
Capacité totale en litres : $totalWineCapacityInLiters
40+
Barriques de la cave :
41+
42+
""".trimIndent()
43+
44+
for(wineBarrel in wineBarrels) {
45+
description += wineBarrel.description() + "\n"
46+
}
47+
48+
return description
49+
}
3450
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package fmt.kotlin.fundamentals
2+
3+
fun main() {
4+
val tooBigBarrel = WineBarrel(600)
5+
6+
val barrel1 = WineBarrel(271)
7+
val barrel2 = WineBarrel(376)
8+
val barrel3 = WineBarrel(642)
9+
val barrel4 = WineBarrel(522)
10+
val barrel5 = WineBarrel(58)
11+
barrel5.age(4)
12+
13+
val barrel6 = WineBarrel(100, barrel5)
14+
15+
val cellar = Cellar("Laurent de Sauve d’Yquem")
16+
cellar.addBarrels(
17+
listOf(
18+
barrel1,
19+
barrel2,
20+
barrel3,
21+
barrel4,
22+
barrel6
23+
)
24+
)
25+
cellar.cellarName = "Joséphine d'Yquem"
26+
cellar.age(8)
27+
println(cellar.description())
28+
println(barrel5.description())
29+
30+
val bottle = Bottle(1)
31+
val wineBottle = WineBottle(
32+
"RED",
33+
bottle
34+
)
35+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,17 @@ class WineBarrel private constructor(
1414
capacityInLiters,
1515
wineBarrel.wineAgeInMonths
1616
)
17+
18+
init {
19+
if (capacityInLiters > 500) {
20+
println("Warning: barrel is high, thus wine won't taste good")
21+
}
22+
}
23+
24+
fun description(): String {
25+
return """
26+
Capacité en litres: $capacityInLiters
27+
Âge du vin : $wineAgeInMonths
28+
""".trimIndent()
29+
}
1730
}

0 commit comments

Comments
 (0)