Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _03.WildFarm
  9. {
  10.     public abstract class Food
  11.     {
  12.         private int quantity;
  13.  
  14.         protected Food(int quantity)
  15.         {
  16.             this.Quantity = quantity;
  17.         }
  18.  
  19.         public int Quantity
  20.         {
  21.             get
  22.             {
  23.                 return quantity;
  24.             }
  25.             set
  26.             {
  27.                 quantity = value;
  28.             }
  29.         }
  30.     }
  31.  
  32.     public abstract class Animal
  33.     {
  34.         private string animalName;
  35.         private string animalType;
  36.         private double animalWeight;
  37.         private int foodEaten;
  38.  
  39.         protected Animal(string animalName, string animalType, double animalWeight)
  40.         {
  41.             this.AnimalName = animalName;
  42.             this.AnimalType = animalType;
  43.             this.AnimalWeight = animalWeight;
  44.             this.FoodEaten = foodEaten;
  45.         }
  46.  
  47.         public string AnimalName
  48.         {
  49.             get
  50.             {
  51.                 return animalName;
  52.             }
  53.             set
  54.             {
  55.                 animalName = value;
  56.             }
  57.         }
  58.  
  59.         public string AnimalType
  60.         {
  61.             get
  62.             {
  63.                 return animalType;
  64.             }
  65.             set
  66.             {
  67.                 animalType = value;
  68.             }
  69.         }
  70.  
  71.         public double AnimalWeight
  72.         {
  73.             get
  74.             {
  75.                 return animalWeight;
  76.             }
  77.             set
  78.             {
  79.                 animalWeight = value;
  80.             }
  81.         }
  82.  
  83.         public int FoodEaten
  84.         {
  85.             get
  86.             {
  87.                 return foodEaten;
  88.             }
  89.             set
  90.             {
  91.                 foodEaten = value;
  92.             }
  93.         }
  94.  
  95.         public abstract void MakeSound();
  96.  
  97.         public abstract void Eat(Food food);
  98.     }
  99.  
  100.     public abstract class Mammal : Animal
  101.     {
  102.         private string livingRegion;
  103.  
  104.         protected Mammal(string animalName, string animalType, double animalWeight, string livingRegion)
  105.             : base(animalName, animalType, animalWeight)
  106.         {
  107.             this.LivingRegion = livingRegion;
  108.         }
  109.  
  110.         public string LivingRegion
  111.         {
  112.             get
  113.             {
  114.                 return livingRegion;
  115.             }
  116.             set
  117.             {
  118.                 livingRegion = value;
  119.             }
  120.         }
  121.  
  122.         public override string ToString()
  123.         {
  124.             return $"{this.AnimalType}[{this.AnimalName}, {this.AnimalWeight}, {this.LivingRegion}, {this.FoodEaten}]";
  125.         }
  126.  
  127.     }
  128.  
  129.     public class Mouse : Mammal
  130.     {
  131.         public Mouse(string animalName, string animalType, double animalWeight, string livingRegion)
  132.             : base(animalName, animalType, animalWeight, livingRegion)
  133.         {
  134.         }
  135.  
  136.         public override void MakeSound()
  137.         {
  138.             Console.WriteLine("SQUEEEAAAK!");
  139.         }
  140.  
  141.         public override void Eat(Food food)
  142.         {
  143.             if (food.GetType().Name != "Vegetable")
  144.             {
  145.                 Console.WriteLine($"{this.AnimalType}s are not eating that type of food!");
  146.             }
  147.             else
  148.             {
  149.                 this.FoodEaten += food.Quantity;
  150.                 Console.WriteLine("A cheese was just eaten!");
  151.             }
  152.         }
  153.  
  154.     }
  155.  
  156.     public class Zebra : Mammal
  157.     {
  158.         public Zebra(string animalName, string animalType, double animalWeight, string livingRegion)
  159.             : base(animalName, animalType, animalWeight, livingRegion)
  160.         {
  161.         }
  162.  
  163.         public override void MakeSound()
  164.         {
  165.             Console.WriteLine("Zs");
  166.         }
  167.  
  168.         public override void Eat(Food food)
  169.         {
  170.             if (food.GetType().Name != "Vegetable")
  171.             {
  172.                 Console.WriteLine($"{this.AnimalType}s are not eating that type of food!");
  173.             }
  174.             else
  175.             {
  176.                 this.FoodEaten += food.Quantity;
  177.             }
  178.         }
  179.     }
  180.  
  181.     public abstract class Felime : Mammal
  182.     {
  183.         public Felime(string animalName, string animalType, double animalWeight, string livingRegion)
  184.             : base(animalName, animalType, animalWeight, livingRegion)
  185.         {
  186.  
  187.         }
  188.     }
  189.  
  190.     public class Cat : Felime
  191.     {
  192.         private string breed;
  193.  
  194.         public Cat(string animalName, string animalType, double animalWeight, string livingRegion, string breed)
  195.             : base(animalName, animalType, animalWeight, livingRegion)
  196.         {
  197.             this.Breed = breed;
  198.         }
  199.  
  200.         public string Breed
  201.         {
  202.             get
  203.             {
  204.                 return breed;
  205.             }
  206.             set
  207.             {
  208.                 breed = value;
  209.             }
  210.         }
  211.  
  212.         public override void MakeSound()
  213.         {
  214.             Console.WriteLine("Meowwww");
  215.         }
  216.  
  217.         public override void Eat(Food food)
  218.         {
  219.             this.FoodEaten += food.Quantity;
  220.         }
  221.  
  222.         public override string ToString()
  223.         {
  224.             return $"{this.AnimalType}[{this.AnimalName}, {this.Breed}, {this.AnimalWeight}, {this.LivingRegion}, {this.FoodEaten}]";
  225.         }
  226.     }
  227.  
  228.     public class Tiger : Felime
  229.     {
  230.         public Tiger(string animalName, string animalType, double animalWeight, string livingRegion)
  231.             : base(animalName, animalType, animalWeight, livingRegion)
  232.         {
  233.         }
  234.  
  235.         public override void MakeSound()
  236.         {
  237.             Console.WriteLine("ROAAR!!!");
  238.         }
  239.  
  240.         public override void Eat(Food food)
  241.         {
  242.             if (food.GetType().Name != "Meat")
  243.             {
  244.                 Console.WriteLine($"{this.AnimalType}s are not eating that type of food!");
  245.             }
  246.             else
  247.             {
  248.                 this.FoodEaten += food.Quantity;
  249.             }
  250.         }
  251.     }
  252.  
  253.     public class Vegetable : Food
  254.     {
  255.         public Vegetable(int quantity)
  256.             : base(quantity)
  257.         {
  258.         }
  259.     }
  260.  
  261.     public class Meat : Food
  262.     {
  263.         public Meat(int quantity)
  264.             : base(quantity)
  265.         {
  266.         }
  267.     }
  268.  
  269.     public class StartUp
  270.     {
  271.         public static void Main()
  272.         {
  273.             string animalInformation = Console.ReadLine();
  274.  
  275.             while (animalInformation != "End")
  276.             {
  277.                 var foodForEat = Console.ReadLine()
  278.                     .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  279.                 var typeFood = foodForEat[0];
  280.                 var foodQuantity = int.Parse(foodForEat[1]);
  281.  
  282.                 Food currentFood = null;
  283.  
  284.                 if (typeFood == "Vegetable")
  285.                 {
  286.                     currentFood = new Vegetable(foodQuantity);
  287.                 }
  288.                 else
  289.                 {
  290.                     currentFood = new Meat(foodQuantity);
  291.                 }
  292.  
  293.  
  294.                 var animalTokens = animalInformation
  295.                     .Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  296.                 var animalType = animalTokens[0];
  297.                 var animalName = animalTokens[1];
  298.                 var animalWeight = double.Parse(animalTokens[2]);
  299.                 var livingRegion = animalTokens[3];
  300.  
  301.                 Animal currentAnimal = null;
  302.  
  303.                 if (animalTokens.Length == 5)
  304.                 {
  305.                     var catBreed = animalTokens[4];
  306.                     currentAnimal = new Cat(animalName,animalType,animalWeight,livingRegion,catBreed);
  307.                 }
  308.                 else
  309.                 {
  310.                     switch (animalType)
  311.                     {
  312.                         case "Tiger":
  313.                             currentAnimal = new Tiger(animalName,animalType,animalWeight,livingRegion);
  314.                             break;
  315.                         case "Zebra":
  316.                             currentAnimal = new Zebra(animalName,animalType,animalWeight,livingRegion);
  317.                             break;
  318.                         case "Mouse":
  319.                             currentAnimal = new Mouse(animalName, animalType, animalWeight, livingRegion);
  320.                             break;
  321.                     }
  322.                 }
  323.  
  324.                 currentAnimal.MakeSound();
  325.                 currentAnimal.Eat(currentFood);
  326.                 Console.WriteLine(currentAnimal);
  327.  
  328.                 animalInformation = Console.ReadLine();
  329.             }
  330.         }
  331.     }
  332. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement