Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. interface BlackAnimal {
  2. color: string;
  3. }
  4.  
  5. interface AnimalWith4Paws {
  6. nbPaws: number;
  7. }
  8.  
  9.  
  10. class Animal implements BlackAnimal, AnimalWith4Paws {
  11. species: string;
  12. nbPaws: number;
  13. color: string;
  14.  
  15. constructor(species: string, nbPaws: number, color: string) {
  16. this.species = species
  17. this.nbPaws = nbPaws
  18. this.color = color
  19. }
  20. }
  21.  
  22.  
  23. class Cat extends Animal {
  24.  
  25. }
  26.  
  27.  
  28. class Dog extends Animal {
  29.  
  30. }
  31.  
  32.  
  33. class Bird extends Animal {
  34.  
  35. }
  36.  
  37.  
  38. class Fish extends Animal {
  39.  
  40. }
  41.  
  42.  
  43. class Insect extends Animal {
  44.  
  45. }
  46.  
  47.  
  48.  
  49. function photographAnimal (all: Animal) {
  50. console.log("I can shoot this animal : " + all.species)
  51. }
  52.  
  53. function catMiaou (chat: Cat) {
  54. console.log("I'm a " + chat.species + ", miaou!")
  55. }
  56.  
  57.  
  58. function dogWoof (chien: Dog) {
  59. console.log("I'm a " + chien.species + ", woof!")
  60. }
  61.  
  62. function birdFly (bird: Bird) {
  63. console.log("I'm a " + bird.species + ", I can fly.")
  64. }
  65.  
  66. function fishSwim (fish: Fish) {
  67. console.log("I'm a " + fish.species + ", I can swim.")
  68. }
  69.  
  70. function animalCaress (paws4: Animal) {
  71. if (paws4.nbPaws === 4) {
  72. console.log("Youpi, I'm a " + paws4.species + " with " + paws4.nbPaws + " paws, caress me!")
  73. } else {
  74. console.log("Shit, no caress for me, I'm a " + paws4.species + " with " + paws4.nbPaws + " paws.")
  75. }
  76.  
  77. }
  78.  
  79. function feedBlackAnimal (feed: Animal) {
  80. if (feed.color === "black") {
  81. console.log("Youpi, I can feed this animal because it's " + feed.color)
  82. } else {
  83. console.log("Shit, I can't feed this animal because it's " + feed.color)
  84. }
  85. }
  86.  
  87.  
  88. let europeanCat = new Animal("cat", 4, "black");
  89. let chartreuxCat = new Animal("cat", 4, "white")
  90. let terreNeuveDog = new Animal("dog", 4, "black")
  91. let moonDog = new Animal("dog", 4, "brown")
  92. let mesange = new Bird("bird", 0, "gray")
  93. let merle = new Bird("bird", 0, "black")
  94. let thon = new Fish("fish", 0, "")
  95. let requin = new Fish("fish", 0, "")
  96. let asticot = new Insect("insect", 0, "")
  97.  
  98.  
  99. photographAnimal(europeanCat)
  100. catMiaou(europeanCat)
  101. dogWoof(terreNeuveDog)
  102. birdFly(mesange)
  103. fishSwim(thon)
  104. feedBlackAnimal(europeanCat)
  105. feedBlackAnimal(chartreuxCat)
  106. feedBlackAnimal(terreNeuveDog)
  107. feedBlackAnimal(moonDog)
  108. feedBlackAnimal(merle)
  109. animalCaress(europeanCat)
  110. animalCaress(terreNeuveDog)
  111. animalCaress(requin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement