tamerSabek

14032019_6

Mar 14th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.60 KB | None | 0 0
  1. import Foundation
  2.  
  3. class Building{
  4.     var floors:Int{
  5.         willSet{
  6.             foundationCount += 1
  7.        }
  8.         didSet{
  9.             moneyspent += 1000
  10.         }
  11.     }
  12.  
  13.     var height:Int{
  14.         get{
  15.             return floors * 10
  16.         }
  17.         set{
  18.             floors = newValue / 10
  19.         }
  20.     }
  21.  
  22.     var foundationCount = 0
  23.     var moneyspent = 0
  24.  
  25.     init (floors:Int){
  26.         self.floors = floors
  27.     }
  28. }
  29.  
  30. let building = Building(floors:3)
  31.  
  32. print(building.floors)
  33. print(building.height)
  34.  
  35. building.height = 20
  36.  
  37. print(building.floors)
  38. print(building.height)
Add Comment
Please, Sign In to add comment