static void Main(string[] args)
        {
            List <Cat> cats = new List <Cat>();

            string readLine = string.Empty;

            while ((readLine = Console.ReadLine()) != "End")
            {
                string[] tokens   = readLine.Split();
                string   breed    = tokens[0];
                string   catName  = tokens[1];
                double   quantity = double.Parse(tokens[2]);

                if (breed == "Siamese")
                {
                    Siamese siamese = new Siamese {
                        Name = catName, EarSize = quantity
                    };
                    cats.Add(siamese);
                }
                else if (breed == "Cymric")
                {
                    Cymric cymric = new Cymric {
                        Name = catName, FurLenght = quantity
                    };
                    cats.Add(cymric);
                }
                else if (breed == "StreetExtraordinaire")
                {
                    StreetExtraordinaire streetExtraordinaire = new StreetExtraordinaire {
                        Name = catName, DecibelsOfMeows = quantity
                    };
                    cats.Add(streetExtraordinaire);
                }
            }
            string searchByName = Console.ReadLine();

            var cat = cats.First(a => a.Name == searchByName);

            Console.WriteLine(cat);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            List <Cat> cats = new List <Cat>();

            while (true)
            {
                string information = Console.ReadLine();

                if (information == "End")
                {
                    break;
                }

                List <string> inputParams = information.Split(' ').ToList();

                if (inputParams[0] == "Siamese")
                {
                    Siamese a = new Siamese(inputParams[1], int.Parse(inputParams[2]));
                    cats.Add(a);
                }
                else if (inputParams[0] == "Cymric")
                {
                    Cymric a = new Cymric(inputParams[1], decimal.Parse(inputParams[2]));
                    cats.Add(a);
                }
                else if (inputParams[0] == "StreetExtraordinaire")
                {
                    StreetExtraordinaire a = new StreetExtraordinaire(inputParams[1], int.Parse(inputParams[2]));
                    cats.Add(a);
                }
            }

            string catName = Console.ReadLine();

            var b = cats.FirstOrDefault(x => x.Name == catName);

            Console.WriteLine(b);
        }
        public static void Main()
        {
            List <Cat> cats  = new List <Cat>();
            string     input = Console.ReadLine();

            while (input != "End")
            {
                string[] inputParts = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   catType    = inputParts[0];
                string   name       = inputParts[1];
                switch (catType)
                {
                case "Siamese":
                    double  earSize = double.Parse(inputParts[2]);
                    Siamese siamese = new Siamese(name, earSize);
                    cats.Add(siamese);
                    break;

                case "Cymric":
                    double furLength = double.Parse(inputParts[2]);
                    Cymric cymric    = new Cymric(name, furLength);
                    cats.Add(cymric);
                    break;

                case "StreetExtraordinaire":
                    double decibelsOfMeows = double.Parse(inputParts[2]);
                    StreetExtraordinaire streetExtraordinaire = new StreetExtraordinaire(name, decibelsOfMeows);
                    cats.Add(streetExtraordinaire);
                    break;
                }
                input = Console.ReadLine();
            }

            string searchedCat = Console.ReadLine();
            Cat    cat         = cats.FirstOrDefault(c => c.Name == searchedCat);

            Console.WriteLine(cat);
        }