Advertisement
Aborigenius

Animals

Aug 20th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Animal
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var dogs = new Dictionary<string, Dog>();
  14.             var cats = new Dictionary<string, Cat>();
  15.             var snakes = new Dictionary<string, Snake>();
  16.  
  17.             string input = Console.ReadLine();
  18.  
  19.             while (input != "I'm your Huckleberry")
  20.             {
  21.                 string[] inputTokens = input.Split(' ');
  22.  
  23.                 string type = inputTokens[0];
  24.                 string name = inputTokens[1];
  25.  
  26.                 if (type == "talk")
  27.                 {
  28.                     if (dogs.ContainsKey(name))
  29.                     {
  30.                         dogs[name].ProduceSound();
  31.                     }
  32.                     if (cats.ContainsKey(name))
  33.                     {
  34.                         cats[name].ProduceSound();
  35.                     }
  36.                     if (snakes.ContainsKey(name))
  37.                     {
  38.                         snakes[name].ProduceSound();
  39.                     }
  40.                 }
  41.                 if (type == "Dog")
  42.                 {
  43.                     name = inputTokens[1];
  44.                     int age = int.Parse(inputTokens[2]);
  45.                     int property = int.Parse(inputTokens[3]);
  46.                     dogs.Add(name, new Dog(name, age, property));
  47.                 }
  48.                 else if (type == "Cat")
  49.                 {
  50.                     name = inputTokens[1];
  51.                     int age = int.Parse(inputTokens[2]);
  52.                     int property = int.Parse(inputTokens[3]);
  53.                     cats.Add(name, new Cat(name, age, property));
  54.                 }
  55.                 else if (type == "Snake")
  56.                 {
  57.                     name = inputTokens[1];
  58.                     int age = int.Parse(inputTokens[2]);
  59.                     int property = int.Parse(inputTokens[3]);
  60.                     snakes.Add(name, new Snake(name, age, property));
  61.                 }
  62.                 input = Console.ReadLine();
  63.             }
  64.  
  65.             foreach (var item in dogs)
  66.             {
  67.                 Dog dog = item.Value;
  68.                 Console.WriteLine($"Dog: {dog.Name}, Age: {dog.Age}, Number Of Legs: {dog.NumberOfLegs}");
  69.             }
  70.             foreach (var item in cats)
  71.             {
  72.                 Cat cat = item.Value;
  73.                 Console.WriteLine($"Cat: {cat.Name}, Age: {cat.Age}, IQ: {cat.IntelligenceQuotient}");
  74.  
  75.             }
  76.             foreach (var item in snakes)
  77.             {
  78.                 Snake snake = item.Value;
  79.                 Console.WriteLine($"Snake: {snake.Name}, Age: {snake.Age}, Cruelty: {snake.CrueltyCoefficient}");
  80.             }
  81.         }
  82.         class Dog
  83.         {
  84.             public string Name { get; set; }
  85.             public int Age { get; set; }
  86.             public int NumberOfLegs { get; set; }
  87.  
  88.             public Dog(string name, int age, int property)
  89.             {
  90.                 this.Name = name;
  91.                 this.Age = age;
  92.                 this.NumberOfLegs = property;
  93.             }
  94.  
  95.             public void ProduceSound()
  96.             {
  97.                 Console.WriteLine("I'm a Distinguishedog, and I will now produce a distinguished sound! Bau Bau.");
  98.             }
  99.         }
  100.  
  101.         class Cat
  102.         {
  103.             public string Name { get; set; }
  104.             public int Age { get; set; }
  105.             public int IntelligenceQuotient { get; set; }
  106.  
  107.             public void ProduceSound()
  108.             { Console.WriteLine("I'm an Aristocat, and I will now produce an aristocratic sound! Myau Myau."); }
  109.  
  110.  
  111.             public Cat(string name, int age, int property)
  112.             {
  113.                 this.Name = name;
  114.                 this.Age = age;
  115.                 this.IntelligenceQuotient = property;
  116.             }
  117.         }
  118.  
  119.         class Snake
  120.         {
  121.             public string Name { get; set; }
  122.             public int Age { get; set; }
  123.             public int CrueltyCoefficient { get; set; }
  124.  
  125.  
  126.             public Snake(string name, int age, int property)
  127.             {
  128.                 this.Name = name;
  129.                 this.Age = age;
  130.                 this.CrueltyCoefficient = property;
  131.             }
  132.  
  133.             public void ProduceSound()
  134.             { Console.WriteLine("I'm a Sophistisnake, and I will now produce a sophisticated sound! Honey, I'm home."); }
  135.         }
  136.  
  137.  
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement