Beispiel #1
0
        static void Main()
        {
            string     input = Console.ReadLine();
            List <Cat> cats  = new List <Cat>();

            while (input != "End")
            {
                string[] catInfo = input.Split();
                string   catType = catInfo[0];
                string   catName = catInfo[1];

                switch (catType)
                {
                case "Siamese":
                    int     earSize = int.Parse(catInfo[2]);
                    Siamese siamese = new Siamese(catType, catName, earSize);
                    cats.Add(siamese);
                    break;

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

                case "StreetExtraordinaire":
                    int decibelsOfMewows = int.Parse(catInfo[2]);
                    StreetExtraordinaire streetExtraordinaire = new StreetExtraordinaire(catType, catName, decibelsOfMewows);
                    cats.Add(streetExtraordinaire);
                    break;

                default:
                    break;
                }

                input = Console.ReadLine();
            }

            string catNameToFind = Console.ReadLine();

            var catFound = cats.Where(c => c.Name == catNameToFind).First();

            Console.WriteLine(catFound.ToString());
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var input = Console.ReadLine();

            while (input != "End" && input != String.Empty)
            {
                var tokens = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                switch (tokens[0])
                {
                case "Siamese": var siamese = new Siamese()
                {
                        Name    = tokens[1],
                        EarSize = int.Parse(tokens[2])
                };
                    cats.Add(siamese);
                    break;

                case "Cymric": var cymric = new Cymric()
                {
                        Name      = tokens[1],
                        FurLength = double.Parse(tokens[2]),
                };
                    cats.Add(cymric);
                    break;

                case "StreetExtraordinaire": var streetExtra = new StreetExtraordinaire()
                {
                        Name            = tokens[1],
                        DecibelsOfMeows = int.Parse(tokens[2])
                };
                    cats.Add(streetExtra);
                    break;
                }

                input = Console.ReadLine();
            }

            var queryName = Console.ReadLine();

            Console.WriteLine(cats[cats.FindIndex(cat => cat.Name == queryName)].ToString());
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var listOfCats = new List <Cat>();

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }
                var split = input.Split(' ').ToArray();
                if (split[0] == "Cymric")
                {
                    var cat = new Cymric(split[1], double.Parse(split[2], CultureInfo.InvariantCulture));
                    listOfCats.Add(cat);
                }
                else if (split[0] == "StreetExtraordinaire")
                {
                    var cat = new StreetExtraordinaire(split[1], int.Parse(split[2]));
                    listOfCats.Add(cat);
                }
                else if (split[0] == "Siamese")
                {
                    var cat = new Siamese(split[1], int.Parse(split[2]));
                    listOfCats.Add(cat);
                }
                else
                {
                    throw new ArgumentException("Wrong type of Cat");
                }
            }
            var searchedCat = Console.ReadLine();

            Console.WriteLine(listOfCats.First(x => x.Name == searchedCat).ToString());
        }
Beispiel #4
0
        private static List <Cat> GetCats()
        {
            var cats = new List <Cat>();

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }

                var catInfo           = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var breed             = catInfo[0];
                var name              = catInfo[1];
                var breedSpecificInfo = catInfo[2];

                Cat cat = new Cat(breed, name);
                switch (breed)
                {
                case "Siamese":
                    cat = new Siamese(breed, name, int.Parse(breedSpecificInfo));
                    break;

                case "Cymric":
                    cat = new Cymric(breed, name, double.Parse(breedSpecificInfo));
                    break;

                case "StreetExtraordinaire":
                    cat = new Extraordinary(breed, name, int.Parse(breedSpecificInfo));
                    break;
                }
                cats.Add(cat);
            }
            return(cats);
        }