Advertisement
Guest User

OOP

a guest
Dec 24th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 3.12 KB | None | 0 0
  1.  
  2. [<AbstractClass>]
  3. type Food(name: string, amount: int) =
  4.     let name = name
  5.     let mutable amount = amount
  6.     let mutable toeat = 0
  7.  
  8.  
  9.  
  10.  
  11.  
  12. type Fruit(name: string, amount: int) =
  13.     inherit Food(name, amount)
  14.     let mutable amountofBananas = amount
  15.     let mutable amountofApples = amount
  16.     member this.amountofBanan = amountofBananas
  17.     member this.amountofApple = amountofApples
  18.     member this.BananGetLess toeat =
  19.             let a = amount - toeat
  20.             match (a) with
  21.             |0 -> amountofBananas <- a
  22.                   printfn "You just have ate the last banan!"
  23.                  
  24.                    
  25.             |_ -> if a > 0 then printfn "It was tasty ^_^"
  26.                                 amountofBananas <- a
  27.                                
  28.                   else  printfn "You don't have any bananas!"
  29.      
  30.    
  31.     member this.AppleGetLess toeat =
  32.             let a = amount - toeat
  33.             match (a) with
  34.             |0 -> amountofApples <- a
  35.                   printfn "You just have ate the last apple!"
  36.                  
  37.                    
  38.             |_ -> if a > 0 then printfn "It was tasty ^_^"
  39.                                 amountofApples <- a
  40.                                
  41.                   else  printfn "You don't have enough apples!"
  42.      
  43.  
  44. let Banan = new Fruit("Banan", 10)
  45. let Apple = new Fruit("Apple", 10)
  46.  
  47. printfn "amount of bananas %A " Banan.amountofBanan
  48.  
  49.  
  50. type Animal(name: string, mood: int) =
  51.     let name = name
  52.     let mutable mood = mood
  53.  
  54.     member this.moodincrease point =
  55.         mood <- mood + point
  56.     member this.eatBanan toeat =
  57.         Banan.BananGetLess toeat
  58.         this.moodincrease 5
  59.     member this.eatApple toeat =
  60.         Apple.AppleGetLess toeat
  61.         this.moodincrease 10
  62.     member this.Drinkcoffee =
  63.         this.moodincrease 40
  64.     member this.Mood = mood
  65.     member this.ReceiveCake  = printfn "%A says : I HATE FISH" name
  66.  
  67. type Cat(name: string, mood: int) =
  68.     inherit Animal(name, mood)
  69.     let mutable lives = 9
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. let Monkey = new Animal("Monkey", 30)
  77. Monkey.eatBanan 10
  78. Monkey.Drinkcoffee
  79. Monkey.ReceiveCake
  80.  
  81. type Human(name: string, skills: int) =
  82.     let name = name
  83.     let f = 1
  84.     let mutable skills = skills
  85.     let mutable amountofcakes = 0
  86.     member this.MakeFishCake =
  87.         amountofcakes <- amountofcakes + 1
  88.         skills <- skills + 1
  89.     member this.PresentCake (animal: Animal) =
  90.         match (amountofcakes) with
  91.         |0 -> printfn "This human doesn't have enough cakes"
  92.         |_ -> if amountofcakes > 0 then animal.ReceiveCake
  93.                                         amountofcakes <- amountofcakes - 1
  94.                                    else printfn "This Human doesn't have enough cakes"
  95.  
  96.        
  97.  
  98. let Tim = new Cat("Tim", 12)                              
  99. let Charls = new Human("Charls", 0)
  100. Charls.PresentCake Monkey
  101. Charls.MakeFishCake
  102. Charls.PresentCake Tim
  103.      
  104.  
  105.  
  106.  
  107. printfn "amount of bananas %A " Banan.amountofBanan
  108. printfn "amount of apples %A " Apple.amountofApple
  109. printfn "Monkey's mood is: %A" Monkey.Mood
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement