Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typealias animal = (type : String, name : String, numOfLegs : Int, voice : String, live : Bool)
- class Lion {
- //Instance variables
- private var _name : String
- private var _numOfLegs : Int
- private var _voice : String
- private var _live : Bool
- //c'tor
- init(name : String) {
- self._name = name
- self._numOfLegs = 4
- self._voice = "wrrrroooorrrr"
- self._live = true
- }
- func eat(food : animal) {
- if food.type != "cow" {
- print("Can eat only cows")
- } else {
- print("Yammi")
- }
- }
- func makeSound() {
- if self._live == true {
- print(self._voice)
- }
- }
- }
- class Cow {
- //Instance variables
- private var _name : String
- private var _numOfLegs : Int
- private var _voice : String
- private var _live : Bool
- //c'tor
- init(name : String) {
- self._name = name
- self._numOfLegs = 4
- self._voice = "mooooo"
- self._live = true
- }
- func makeSound() {
- if self._live == true {
- print(self._voice)
- }
- }
- }
- class Cat {
- //Instance variables
- private var _name : String
- private var _numOfLegs : Int
- private var _voice : String
- private var _live : Bool
- //c'tor
- init(name : String) {
- self._name = name
- self._numOfLegs = 4
- self._voice = "miaaaooooo"
- self._live = true
- }
- func eat(food : animal) {
- if food.type != "Mouse" {
- print("Can eat only mice")
- } else {
- print("Yammi")
- }
- }
- func drink(food : animal) {
- if food.type != "Cow" && food.live == true {
- print("Can drink only from cows")
- }
- }
- func makeSound() {
- if self._live == true {
- print(self._voice)
- }
- }
- }
- class Mouse {
- //Instance variables
- private var _name : String
- private var _numOfLegs : Int
- private var _voice : String
- private var _live : Bool
- //c'tor
- init(name : String) {
- self._name = name
- self._numOfLegs = 4
- self._voice = "tsftsftsfstf"
- self._live = true
- }
- func makeSound() {
- if self._live == true {
- print(self._voice)
- }
- }
- }
- var lion = Lion(name : "Mufasa")
- var cow : animal = ("cow", "Dolly", 4, "mooooo", true)
- var jerry : animal = ("lion", "Jerry", 4, "wrrroorrr", true)
- var mitsi = Cat(name : "Mitsi")
- lion.eat(food: cow)
- mitsi.eat(food: cow)
- mitsi.drink(food: cow)
- mitsi.makeSound()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement