@@ -6,29 +6,31 @@ sealed class Container(
66) {
77    val  valid =  (possibleCapacities).contains(capacity)
88
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-     }
9+     open  fun  containersNeededToPourIn (container :  Container ) =  capacity /  container.capacity
2110}
2211
2312class  Barrel (
2413    capacity :  Int 
25- ) : Container(capacity, 20000 ..40000 )
14+ ) : Container(capacity, 20000 ..40000 ) {
15+ 
16+     override  fun  containersNeededToPourIn (container :  Container ) =  when  (container) {
17+         is  Barrel , is  Tank  ->  - 1 
18+         else  ->  super .containersNeededToPourIn(container)
19+     }
20+ }
2621
2722class  Tank (
2823    capacity :  Int 
29- ) : Container(capacity, 2000000 ..10000000 )
24+ ) : Container(capacity, 2000000 ..10000000 ) {
25+ 
26+     override  fun  containersNeededToPourIn (container :  Container ) =  if  (container is  Tank ) {
27+         - 1 
28+     } else  super .containersNeededToPourIn(container)
29+ }
3030
31- sealed  class  FixedVolumeContainer (capacity :  Int ) : Container(capacity, capacity..capacity)
31+ sealed  class  FixedVolumeContainer (capacity :  Int ) : Container(capacity, capacity..capacity) {
32+     override  fun  containersNeededToPourIn (container :  Container ) =  - 1 
33+ }
3234
3335class  Magnum  : FixedVolumeContainer (150 )
3436class  Bottle  : FixedVolumeContainer (75 )
0 commit comments