File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed 
tp4/src/main/kotlin/fmt/kotlin/fundamentals Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 11package  fmt.kotlin.fundamentals 
22
3- abstract  class  Container (
3+ sealed  class  Container (
44    val  capacity :  Int ,
55    possibleCapacities :  IntRange 
66) {
77    val  valid =  (possibleCapacities).contains(capacity)
88
9-     fun  containersNeededToPourIn (container :  Container ) =  - 1 
9+     fun  containersNeededToPourIn (container :  Container ) =  when  (this ) {
10+         is  Tank  ->  when  (container) {
11+             is  Barrel , is  FixedVolumeContainer  ->  capacity /  container.capacity
12+             is  Tank  ->  - 1 
13+         }
14+ 
15+         is  Barrel  ->  if  (container is  FixedVolumeContainer ) {
16+             capacity /  container.capacity
17+         } else  - 1 
18+ 
19+         is  FixedVolumeContainer  ->  - 1 
20+     }
1021}
1122
1223class  Barrel (
@@ -17,7 +28,7 @@ class Tank(
1728    capacity :  Int 
1829) : Container(capacity, 2000000 ..10000000 )
1930
20- abstract  class  FixedVolumeContainer (capacity :  Int ) : Container(capacity, capacity..capacity)
31+ sealed  class  FixedVolumeContainer (capacity :  Int ) : Container(capacity, capacity..capacity)
2132
2233class  Magnum  : FixedVolumeContainer (150 )
2334class  Bottle  : FixedVolumeContainer (75 )
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments