Advertisement
YavorGrancharov

Animals(class)

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