Beispiel #1
0
        static void Main(string[] args)
        {
            Cat    cat   = new Cat();
            string input = "";

            while ((input = Console.ReadLine()) != "End")
            {
                string[] catInfo = input.Split();
                string   breed   = catInfo[0];

                switch (breed)
                {
                case "Siamese":
                    Siamese siamese = new Siamese(catInfo[1], double.Parse(catInfo[2]));
                    cat.Siamese.Add(siamese);
                    break;

                case "Cymric":
                    Cymric cymric = new Cymric(catInfo[1], double.Parse(catInfo[2]));
                    cat.Cymric.Add(cymric);
                    break;

                case "StreetExtraordinaire":
                    StreetExtraordinaire streetExtraordinaire = new StreetExtraordinaire(catInfo[1], double.Parse(catInfo[2]));
                    cat.StreetExtraordinaire.Add(streetExtraordinaire);
                    break;
                }
            }

            string printCat = Console.ReadLine();

            PrintOutput(cat, printCat);
        }
Beispiel #2
0
        public static void Main()
        {
            string     input;
            List <Cat> cats = new List <Cat>();

            while ((input = Console.ReadLine()) != "End")
            {
                string[] catInfo = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                string   breed   = catInfo[0];
                string   name    = catInfo[1];

                if (breed == "Siamese")
                {
                    int earSize    = int.Parse(catInfo[2]);
                    Cat siameseCat = new Siamese(name, earSize);

                    cats.Add(siameseCat);
                }
                else if (breed == "Cymric")
                {
                    double furLength = double.Parse(catInfo[2]);

                    Cat cymricCat = new Cymric(name, furLength);

                    cats.Add(cymricCat);
                }
                else if (breed == "StreetExtraordinaire")
                {
                    int meowingDecibels = int.Parse(catInfo[2]);

                    Cat streetCat = new StreetExtraordinaire(name, meowingDecibels);

                    cats.Add(streetCat);
                }
            }

            string catName = Console.ReadLine();

            Cat cat = cats.FirstOrDefault(c => c.Name == catName);

            Console.WriteLine(cat);
        }
Beispiel #3
0
        public static void Main()
        {
            var input = Console.ReadLine();
            var cats  = new List <Cat>();

            while (input != "End")
            {
                var   tokens    = input.Split();
                var   breedType = tokens[0];
                var   name      = tokens[1];
                var   spec      = double.Parse(tokens[2]);
                Breed breed     = null;

                if (breedType == "Siamese")
                {
                    breed = new Siamese(breedType, spec);
                }
                else if (breedType == "Cymric")
                {
                    breed = new Cymric(breedType, spec);
                }
                else if (breedType == "StreetExtraordinaire")
                {
                    breed = new StreetExtraordinaire(breedType, spec);
                }

                var cat = new Cat(name, breed);
                cats.Add(cat);

                input = Console.ReadLine();
            }

            var catName     = Console.ReadLine();
            var catForPrint = cats.First(c => c.Name == catName);

            Console.WriteLine($"{catForPrint.Breed.Type} {catForPrint.Name} {catForPrint.Breed}");
        }
        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 StreetExtraordinaire(breed, name, int.Parse(breedSpecificInfo));
                    break;
                }
                cats.Add(cat);
            }
            return(cats);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');

            Cat cat = new Cat();

            while (input.Length > 1)
            {
                var type      = input[0];
                var name      = input[1];
                var parameter = double.Parse(input[2]);

                switch (type)
                {
                case "Siamese":
                    Siamese siamese = new Siamese();

                    siamese.Name    = name;
                    siamese.EarSize = parameter;

                    cat.Siamese.Add(siamese);
                    break;

                case "Cymric":
                    Cymric cymric = new Cymric();

                    cymric.Name      = name;
                    cymric.FurLenght = parameter;

                    cat.Cymric.Add(cymric);
                    break;

                case "StreetExtraordinaire":
                    StreetExtraordinaire street = new StreetExtraordinaire();

                    street.Name           = name;
                    street.DecibelsOfMeow = parameter;

                    cat.StreetExtraordinaire.Add(street);
                    break;
                }

                input = Console.ReadLine().Split(' ');
            }

            string catInfo = Console.ReadLine();

            if (cat.Cymric.Any(x => x.Name.Equals(catInfo)))
            {
                foreach (var currentCat in cat.Cymric)
                {
                    if (currentCat.Name == catInfo)
                    {
                        Console.WriteLine($"Cymric {catInfo} {currentCat.FurLenght:f2}");
                    }
                }
            }
            else if (cat.Siamese.Any(x => x.Name.Equals(catInfo)))
            {
                foreach (var currCat in cat.Siamese)
                {
                    if (currCat.Name.Equals(catInfo))
                    {
                        Console.WriteLine($"Siamese {currCat.Name} {currCat.EarSize}");
                    }
                }
            }
            else if (cat.StreetExtraordinaire.Any(x => x.Name.Equals(catInfo)))
            {
                foreach (var currCat in cat.StreetExtraordinaire)
                {
                    if (currCat.Name.Equals(catInfo))
                    {
                        Console.WriteLine($"StreetExtraordinaire {currCat.Name} {currCat.DecibelsOfMeow}");
                    }
                }
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            string input     = Console.ReadLine();
            var    hierarchy = new Hierarchy(new List <Cymric>(), new List <Siamese>(), new List <StreetExtraordinaire>());

            while (input != "End")
            {
                string[] catData = input.Split(' ');

                string typeCat = catData[0];
                switch (typeCat)
                {
                case "Cymric":
                    var cymric = new Cymric(catData[1], double.Parse(catData[2]));
                    hierarchy.Cymric.Add(cymric);
                    break;

                case "Siamese":
                    var siamese = new Siamese(catData[1], catData[2]);
                    hierarchy.Siamese.Add(siamese);
                    break;

                case "StreetExtraordinaire":
                    var street = new StreetExtraordinaire(catData[1], catData[2]);
                    hierarchy.Street.Add(street);
                    break;
                }

                input = Console.ReadLine();
            }

            string catName = Console.ReadLine();

            if (hierarchy.Siamese.Any(n => n.Name == catName))
            {
                string ear = "";
                foreach (var i in hierarchy.Siamese)
                {
                    if (i.Name == catName)
                    {
                        ear = i.EarSize;
                    }
                }
                Console.WriteLine("Siamese " + catName + $" {ear}");
            }
            else if (hierarchy.Street.Any(n => n.Name == catName))
            {
                string decibel = "";
                foreach (var i in hierarchy.Street)
                {
                    if (i.Name == catName)
                    {
                        decibel = i.Decibels;
                    }
                }
                Console.WriteLine("StreetExtraordinaire " + catName + $" {decibel}");
            }
            else
            {
                double fur = 0;
                foreach (var i in hierarchy.Cymric)
                {
                    if (i.Name == catName)
                    {
                        fur = i.FurLength;
                    }
                }
                Console.WriteLine("Cymric " + catName + $" {fur:f2}");
            }
        }