Skip to content

Commit bd85a50

Browse files
committed
tp5 step 2 solution
1 parent a8472d4 commit bd85a50

File tree

1 file changed

+14
-1
lines changed
  • tp5/src/main/kotlin/fmt/kotlin/fundamentals

1 file changed

+14
-1
lines changed

tp5/src/main/kotlin/fmt/kotlin/fundamentals/Bottle.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@ package fmt.kotlin.fundamentals
22

33
data class Bottle(
44
val name: String,
5-
val year: Int
5+
val year: Int,
6+
val color: WineColor
67
) {
78

89
fun isEqualTo(bottle: Bottle) = this == bottle
910

1011
fun isSameInstance(bottle: Bottle) = this === bottle
12+
13+
override fun toString() = "Bouteille de $name ${color.translate()} de $year"
14+
}
15+
16+
enum class WineColor {
17+
RED,
18+
WHITE;
19+
20+
fun translate() = when (this) {
21+
RED -> "rouge"
22+
WHITE -> "blanc"
23+
}
1124
}

0 commit comments

Comments
 (0)