File tree Expand file tree Collapse file tree 3 files changed +30
-10
lines changed 
tp7/src/main/kotlin/fmt/kotlin/fundamentals Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Original file line number Diff line number Diff line change 11package  fmt.kotlin.fundamentals 
22
33data class  Cellar (val  bottles :  List <WineBottle >) {
4- 
4+     fun  describeBottles (descriptionBuilder :  (WineBottle ) ->  String ) {
5+         for (i in  bottles.indices) {
6+             println (" $i : ${descriptionBuilder(bottles[i])} "  )
7+         }
8+     }
59}
Original file line number Diff line number Diff line change 11package  fmt.kotlin.fundamentals 
22
3- val  buildWineBottleDescription:  (WineBottle ) ->  String  =  {
4-     val  bottleType =  when (it.wineType) {
5-         WineType .RED  ->  " rouge" 
6-         WineType .WHITE  ->  " blanc" 
7-         WineType .ROSE  ->  " rosé" 
8-     }
9- 
10-     " Vin $bottleType  de l'année ${it.year} " 
3+ val  buildWineBottleShortDescription:  (WineBottle ) ->  String  =  {
4+     " Vin ${buildWineTypeDescription(it.wineType)}  de l'année ${it.year} " 
115}
126
137fun  main () {
@@ -31,4 +25,23 @@ fun main() {
3125            2.0 
3226        ),
3327    ))
34- }
28+ 
29+     cellar.describeBottles(buildWineBottleShortDescription)
30+ 
31+     cellar.describeBottles({
32+         " Vin ${buildWineTypeDescription(it.wineType)}  de l'année ${it.year} , "   + 
33+                 " cépage ${it.grapeVariety} , bouteille de ${it.volumeInLiters}  litres" 
34+     })
35+     cellar.describeBottles {
36+         " Vin ${buildWineTypeDescription(it.wineType)}  de l'année ${it.year} , "   + 
37+                 " cépage ${it.grapeVariety} , bouteille de ${it.volumeInLiters}  litres" 
38+     }
39+     cellar.describeBottles(WineBottle ::describe)
40+ }
41+ 
42+ fun  buildWineTypeDescription (wineType :  WineType ): String  = 
43+     when  (wineType) {
44+         WineType .RED  ->  " rouge" 
45+         WineType .WHITE  ->  " blanc" 
46+         WineType .ROSE  ->  " rosé" 
47+     }
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ data class WineBottle(
66    val  grapeVariety :  String ,
77    val  volumeInLiters :  Double 
88) {
9+     fun  describe (): String  {
10+         return  " Vin ${buildWineTypeDescription(wineType)}  de l'année $year " 
11+     }
912}
1013
1114enum  class  WineType  {
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments