File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed 
tp3/src/main/kotlin/fmt/kotlin/fundamentals Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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}
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments