Exemple #1
0
    private static void CatsOrganizer(string inputLine)
    {
        List <string> dataList = inputLine.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();

        string catKind = dataList[0];

        dataList.RemoveAt(0);

        Cat cat;

        switch (catKind)
        {
        case "Siamese":

            cat = new Siamese(dataList[0], int.Parse(dataList[1]));
            break;

        case "Cymric":

            cat = new Cymric(dataList[0], double.Parse(dataList[1]));
            break;

        case "StreetExtraordinaire":

            cat = new StreetExtraordinaire(dataList[0], int.Parse(dataList[1]));
            break;

        default:
            throw new ArgumentException("ni staa");
        }

        ginka.Add(cat);
    }
Exemple #2
0
    static void Main()
    {
        var input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        var cats  = new List <Cat>();

        while (input[0] != "End")
        {
            switch (input[0])
            {
            case "Siamese":
                var siamese = new Siamese(input[1], double.Parse(input[2]));
                cats.Add(siamese);
                break;

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

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

            input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }

        var catName = Console.ReadLine();

        Console.WriteLine(cats.FirstOrDefault(c => c.Name == catName).ToString());
    }
        private static void GetCats(List <Cat> cats)
        {
            string catData = String.Empty;

            while ((catData = Console.ReadLine()) != "End")
            {
                string[] tokens         = catData.Split();
                string   name           = tokens[1];
                string   breed          = tokens[0];
                string   characteristic = tokens[2];

                Cat newCat = new Cat(name, breed);

                switch (breed)
                {
                case "Siamese":
                    newCat = new Siamese(int.Parse(characteristic), name, breed);
                    break;

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

                case "StreetExtraordinaire":
                    newCat = new StreetExtraordinaire(int.Parse(characteristic), name, breed);
                    break;

                default:
                    break;
                }

                cats.Add(newCat);
            }
        }
    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;

            default: break;
            }
            cats.Add(cat);
        }
        return(cats);
    }
Exemple #5
0
    public string GetMeTheDamnCat(string catName)
    {
        StringBuilder sb = new StringBuilder();

        Siamese siamCat = this.SiameseCats.FirstOrDefault(x => x.Name == catName);

        if (siamCat != null)
        {
            sb.AppendLine($"Siamese {siamCat.Name} {siamCat.EarSize}");
            return(sb.ToString().TrimEnd());
        }

        Cymric cymrCat = this.CymricCats.FirstOrDefault(x => x.Name == catName);

        if (cymrCat != null)
        {
            sb.AppendLine($"Cymric {cymrCat.Name} {cymrCat.FurLength:F2}");
            return(sb.ToString().TrimEnd());
        }

        StreetExtraordinaire streetCat = this.StreetExtraordinaireCats.FirstOrDefault(x => x.Name == catName);

        if (streetCat != null)
        {
            sb.AppendLine($"StreetExtraordinaire {streetCat.Name} {streetCat.MeowDecibels}");
            return(sb.ToString().TrimEnd());
        }
        return(string.Empty);
    }
    public static void Main()
    {
        string input = string.Empty;
        var    cats  = new List <Cat>();

        while ((input = Console.ReadLine()) != "End")
        {
            var    catInfo = input.Split();
            string breed   = catInfo[0];
            string name    = catInfo[1];
            Cat    cat     = null;
            switch (breed.ToLower())
            {
            case "siamese":
                int earSize = int.Parse(catInfo[2]);
                cat = new Siamese(name, earSize);
                break;

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

            case "streetextraordinaire":
                int decibels = int.Parse(catInfo[2]);
                cat = new StreetExtraordinaire(name, decibels);
                break;

            default:
                break;
            }
            cats.Add(cat);
        }
        input = Console.ReadLine();

        var currentCat = cats.SingleOrDefault(x => x.Name == input);

        switch (currentCat)
        {
        case Siamese s:
            Console.WriteLine(s);
            break;

        case Cymric c:
            Console.WriteLine(c);
            break;

        case StreetExtraordinaire str:
            Console.WriteLine(str);
            break;

        default:
            break;
        }
    }
Exemple #7
0
    public static void Main()
    {
        var input = Console.ReadLine();

        var cats = new List <ICat>();

        while (input != "End")
        {
            var com = input.Split();

            if (com[0] == "Siamese")
            {
                ICat cat = new Siamese(com[0], com[1], int.Parse(com[2]));
                cats.Add(cat);
            }

            else if (com[0] == "Cymric")
            {
                ICat cat = new Cymric(com[0], com[1], double.Parse(com[2]));
                cats.Add(cat);
            }

            else if (com[0] == "StreetExtraordinaire")
            {
                ICat cat = new StreetExtraordinaire(com[0], com[1], int.Parse(com[2]));
                cats.Add(cat);
            }

            input = Console.ReadLine();
        }

        var name = Console.ReadLine();

        foreach (var x in cats)
        {
            var SiameseAsCat = x as Siamese;
            var CymricAsCat  = x as Cymric;
            var StreetExtraordinaireAsCat = x as StreetExtraordinaire;

            if (SiameseAsCat != null && SiameseAsCat.Name == name)
            {
                Console.WriteLine(SiameseAsCat);
            }

            else if (CymricAsCat != null && CymricAsCat.Name == name)
            {
                Console.WriteLine(CymricAsCat);
            }

            else if (StreetExtraordinaireAsCat != null && StreetExtraordinaireAsCat.Name == name)
            {
                Console.WriteLine(StreetExtraordinaireAsCat);
            }
        }
    }
Exemple #8
0
    private static void Main()
    {
        string     line = Console.ReadLine();
        List <Cat> cats = new List <Cat>();

        while (line != "End")
        {
            string[] items    = line.Split();
            string   catType  = items[0];
            string   catName  = items[1];
            decimal  inicials = decimal.Parse(items[2]);

            switch (catType)
            {
            case "Siamese":
                Cat cat1 = new Siamese
                {
                    EarSize = inicials,
                    Name    = catName
                };

                cats.Add(cat1);
                break;

            case "Cymric":
                Cat cat2 = new Cymric
                {
                    FurLength = inicials,
                    Name      = catName
                };

                cats.Add(cat2);
                break;

            case "StreetExtraordinaire":
                Cat cat3 = new StreetExtraordinaire
                {
                    DecibelsOfMeows = inicials,
                    Name            = catName
                };

                cats.Add(cat3);
                break;
            }

            line = Console.ReadLine();
        }

        string name = Console.ReadLine();

        Cat result = cats.First(cat => cat.Name == name);

        Console.WriteLine(result.ToString());
    }
Exemple #9
0
    public static void Main()
    {
        string input;
        var    cats = new List <Cat>();

        while ((input = Console.ReadLine()) != "End")
        {
            var tokens = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var breed  = tokens[0];

            switch (breed)
            {
            case "Siamese":
                Cat cat = new Siamese
                {
                    Breed   = breed,
                    Name    = tokens[1],
                    EarSize = int.Parse(tokens[2])
                };

                cats.Add(cat);
                break;

            case "Cymric":
                Cat cymric = new Cymric
                {
                    Breed     = breed,
                    Name      = tokens[1],
                    FurLength = double.Parse(tokens[2])
                };

                cats.Add(cymric);
                break;

            case "StreetExtraordinaire":
                Cat streetExtraordinaire = new StreetExtraordinaire
                {
                    Breed    = breed,
                    Name     = tokens[1],
                    Decibels = int.Parse(tokens[2])
                };

                cats.Add(streetExtraordinaire);
                break;
            }
        }

        var name   = Console.ReadLine();
        var result = cats.Where(c => c.Name == name).FirstOrDefault();

        Console.WriteLine(result.ToString());
    }
    static void Main()
    {
        List <Cat> cats = new List <Cat>();

        string inputLine;

        while ((inputLine = Console.ReadLine()) != "End")
        {
            var catInfo  = inputLine.Split();
            var catType  = catInfo[0];
            var catName  = catInfo[1];
            var catParam = catInfo[2];

            switch (catType)
            {
            case "Siamese":
                var siamese = new Siamese()
                {
                    Name    = catName,
                    EarSize = int.Parse(catParam)
                };
                cats.Add(siamese);
                break;

            case "Cymric":
                var cymric = new Cymric()
                {
                    Name      = catName,
                    FurLength = double.Parse(catParam)
                };
                cats.Add(cymric);
                break;

            case "StreetExtraordinaire":
                var streetExtraordinaire = new StreetExtraordinaire()
                {
                    Name            = catName,
                    DecibelsOfMeows = int.Parse(catParam)
                };
                cats.Add(streetExtraordinaire);
                break;

            default:
                break;
            }
        }

        var queryCat  = Console.ReadLine();
        var chosenCat = cats.First(c => c.Name == queryCat);

        Console.WriteLine(chosenCat);
    }
Exemple #11
0
    static void Main(string[] args)
    {
        List <Cat> cats = new List <Cat>();

        string comand = "";

        while (comand != "End")

        {
            comand = Console.ReadLine();
            if (comand == "End")
            {
                break;
            }

            if (comand == "Siamese")
            {
                Siamese time1 = new Siamese();
                time1.name    = Console.ReadLine();
                time1.earSize = Convert.ToDouble(Console.ReadLine());
                cats.Add(time1);
            }
            if (comand == "Cymric")
            {
                Cymric time2 = new Cymric();
                time2.name    = Console.ReadLine();
                time2.furSize = Convert.ToDouble(Console.ReadLine());
                cats.Add(time2);
            }
            if (comand == "StreetExtraordinaire")
            {
                StreetExtraordinaire time3 = new StreetExtraordinaire();
                time3.name    = Console.ReadLine();
                time3.meavPow = Convert.ToInt32(Console.ReadLine());
                cats.Add(time3);
            }
        }
        Console.WriteLine("Wats Cat Name:");
        comand = Console.ReadLine();

        for (int i = 0; i < cats.Count; i++)
        {
            if (cats[i].name == comand)
            {
                Console.WriteLine($"{cats[i].GetType()} {cats[i].name} {cats[i].ToString()}");
            }
        }
        Console.ReadLine();
    }
    static void Main()  // 100/100
    {
        var cats = new List <Cat>();

        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            var    inputDetails = input.Split();
            var    breed        = inputDetails[0];
            string name         = inputDetails[1];

            switch (breed)
            {
            case "Siamese":
                var earSize = int.Parse(inputDetails[2]);
                var siamese = new Siamese(earSize);
                siamese.Name  = name;
                siamese.Breed = breed;
                cats.Add(siamese);     // защото и тя е подклас на Cat

                break;

            case "Cymric":
                var furLength = double.Parse(inputDetails[2]);
                var cymric    = new Cymric(furLength);
                cymric.Name  = name;
                cymric.Breed = breed;
                cats.Add(cymric);

                break;

            case "StreetExtraordinaire":
                var decibel = int.Parse(inputDetails[2]);
                var street  = new StreetExtraordinaire(decibel);
                street.Name  = name;
                street.Breed = breed;
                cats.Add(street);
                break;
            }
        }
        var surchedCat = Console.ReadLine();
        Cat faundedCat = cats.FirstOrDefault(c => c.Name == surchedCat);

        Console.WriteLine(faundedCat.ToString());
    }
Exemple #13
0
    static void Main(string[] args)
    {
        Cat cats = new Cat();

        string cat;

        while ((cat = Console.ReadLine()) != "End")
        {
            string[] CatInfo =
                cat
                .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                .ToArray();

            string  catBreed         = CatInfo[0];
            string  catName          = CatInfo[1];
            decimal catLastParameter = decimal.Parse(CatInfo[2]);

            switch (catBreed)
            {
            case "Siamese":
            {
                Siamese siamese = new Siamese(catName, catBreed, catLastParameter);
                cats.AddSiamese(siamese);
            }
            break;

            case "Cymric":
            {
                Cymric Cymric = new Cymric(catName, catBreed, catLastParameter);
                cats.AddCymric(Cymric);
            }
            break;

            case "StreetExtraordinaire":
            {
                Street_Extraordinaire streetCat = new Street_Extraordinaire(catName, catBreed, catLastParameter);
                cats.AddStreetCat(streetCat);
            }
            break;
            }
        }
        CatPrinter printer = new CatPrinter(cats);
        string     bestCat = Console.ReadLine();

        Console.WriteLine(printer.PrintCat(bestCat, cats));
    }
Exemple #14
0
    public static void Main()
    {
        List <Cat> cats = new List <Cat>();

        while (true)
        {
            string[] line = Console.ReadLine().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                            .ToArray();
            if (line[0] == "End")
            {
                break;
            }

            Cat cat = new Cat();

            if (line[0] == "Siamese")
            {
                cat = new Siamese {
                    EarSize = int.Parse(line[2]), Name = line[1]
                }
            }
            ;
            else if (line[0] == "Cymric")
            {
                cat = new Cymric {
                    FurSize = double.Parse(line[2]), Name = line[1]
                }
            }
            ;
            else
            {
                cat = new StreetExtraordinaire {
                    DbsMeows = int.Parse(line[2]), Name = line[1]
                }
            };
            cats.Add(cat);
        }
        string wantedName = Console.ReadLine();
        Cat    theCat     = cats.Find(x => x.Name.Equals(wantedName));

        Console.WriteLine(theCat.ToString());
    }
}
Exemple #15
0
    public static void Main()
    {
        string line;
        var    cats = new List <Cat>();

        while ((line = Console.ReadLine()) != "End")
        {
            var splitLine = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var breedOfCat = splitLine[0];
            var name       = splitLine[1];
            Cat cat;

            switch (breedOfCat)
            {
            case "StreetExtraordinaire":
                var decibelsOfMeows = int.Parse(splitLine[2]);
                cat = new StreetExtraordinaire(name, decibelsOfMeows);
                cats.Add(cat);
                break;

            case "Siamese":
                var earSize = int.Parse(splitLine[2]);
                cat = new Siamese(name, earSize);
                cats.Add(cat);
                break;

            case "Cymric":
                var furLength = double.Parse(splitLine[2]);
                cat = new Cymric(name, furLength);
                cats.Add(cat);
                break;
            }
        }

        var inputName = Console.ReadLine();

        var choosenOne = cats.SingleOrDefault(c => c.Name == inputName);

        Console.WriteLine(choosenOne);
    }
    public static void Main()
    {
        var cats = new List <Cat>();

        string input;

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

            Cat cat = new Cat(name, breed);

            switch (breed)
            {
            case "Siamese":
                int earSize = int.Parse(tokens[2]);
                cat = new Siamese(name, breed, earSize);
                break;

            case "Cymric":
                double furLength = double.Parse(tokens[2]);
                cat = new Cymric(name, breed, furLength);
                break;

            case "StreetExtraordinaire":
                int decibelsOfMeows = int.Parse(tokens[2]);
                cat = new StreetExtraordinaire(name, breed, decibelsOfMeows);
                break;
            }

            cats.Add(cat);
        }

        string catInput  = Console.ReadLine();
        var    neededCat = cats.FirstOrDefault(c => c.Name == catInput);

        Console.WriteLine(neededCat);
    }
    static void Main(string[] args)
    {
        List <Cat> cats = new List <Cat>();
        string     input;

        while ((input = Console.ReadLine()) != "End")
        {
            string[] inputTokens = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string   breed       = inputTokens[0];
            string   name        = inputTokens[1];
            Cat      cat         = new Cat(breed, name);
            switch (breed)
            {
            case "Siamese":
                int earSize = int.Parse(inputTokens[2]);
                cat = new Siamese(breed, name, earSize);
                break;

            case "Cymric":
                double furLength = double.Parse(inputTokens[2]);
                cat = new Cymric(breed, name, furLength);
                break;

            case "StreetExtraordinaire":
                int decibelsOfMeows = int.Parse(inputTokens[2]);
                cat = new StreetExtraordinaire(breed, name, decibelsOfMeows);
                break;

            default: break;
            }
            cats.Add(cat);
        }
        string wantedCatName = Console.ReadLine();

        //if(cats.Any(c => c.Name == wantedCatName))
        //{
        Console.WriteLine(cats.Find(c => c.Name == wantedCatName));
        //}
    }
    static void Main(string[] args)
    {
        List <Cat> cats = new List <Cat>();
        string     command;

        while ((command = Console.ReadLine()) != "End")
        {
            var    tokens = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            string breed  = tokens[0];
            string name   = tokens[1];
            Cat    cat    = null;

            switch (breed)
            {
            case "Siamese":
                var earSize = int.Parse(tokens[2]);
                cat = new Siamese(name, earSize);
                break;

            case "Cymric":
                var furLength = decimal.Parse(tokens[2]);
                cat = new Cymric(name, furLength);
                break;

            case "StreetExtraordinaire":
                var decibelsOfMeows = int.Parse(tokens[2]);
                cat = new StreetExtraordinaire(name, decibelsOfMeows);
                break;
            }

            cats.Add(cat);
        }

        string catName = Console.ReadLine();

        Cat catToPrint = cats.First(c => c.Name == catName);

        Console.WriteLine(catToPrint);
    }
Exemple #19
0
    static void Main()
    {
        List <Cat> catList = new List <Cat>();

        string input = Console.ReadLine();

        while (input != "End")
        {
            string[] tokens = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            string breed = tokens[0];
            string name  = tokens[1];
            switch (breed)
            {
            case "Siamese":
                Siamese siamCat = new Siamese(name, breed, int.Parse(tokens[2]));
                catList.Add(siamCat);
                break;

            case "Cymric":
                Cymric cymCat = new Cymric(name, breed, double.Parse(tokens[2]));
                catList.Add(cymCat);
                break;

            case "StreetExtraordinaire":
                StreetExtraordinaire streetCat = new StreetExtraordinaire(name, breed, int.Parse(tokens[2]));
                catList.Add(streetCat);
                break;
            }

            input = Console.ReadLine();
        }

        string catToPrint = Console.ReadLine();

        Cat cat = catList.FirstOrDefault(c => c.Name == catToPrint);

        Console.WriteLine(cat);
    }
Exemple #20
0
    public static void Main()
    {
        Dictionary <string, Cat> cats = new Dictionary <string, Cat>();

        string input;

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

            string breed     = catParams[0];
            string name      = catParams[1];
            double parameter = double.Parse(catParams[2]);

            Cat cat = null;

            switch (breed)
            {
            case "Siamese":
                cat = new Siamese(name, parameter);
                break;

            case "Cymric":
                cat = new Cymric(name, parameter);
                break;

            case "StreetExtraordinaire":
                cat = new StreetExtraordinaire(name, parameter);
                break;
            }

            cats[name] = cat;
        }

        string requestedName = Console.ReadLine();

        Console.WriteLine(cats[requestedName]);
    }
Exemple #21
0
    static void Main(string[] args)
    {
        var command = Console.ReadLine();
        var cats    = new List <Cat>();

        while (command != "End")
        {
            var    info  = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string name  = info[1];
            string breed = info[0];

            switch (breed)
            {
            case "Siamese":
                int earSize = int.Parse(info[2]);
                var newSiam = new Siamese(name, breed, earSize);
                cats.Add(newSiam);
                break;

            case "Cymric":
                double furLength = double.Parse(info[2]);
                var    newCymric = new Cymric(name, breed, furLength);
                cats.Add(newCymric);
                break;

            case "StreetExtraordinaire":
                int decibelsOfMeows = int.Parse(info[2]);
                var newStreetExtr   = new StreetExtraordinaire(name, breed, decibelsOfMeows);
                cats.Add(newStreetExtr);
                break;
            }
            command = Console.ReadLine();
        }
        var catName = Console.ReadLine();
        var cat     = cats.FirstOrDefault(x => x.Name == catName);

        Console.WriteLine(cat);
    }
Exemple #22
0
    private static void AddCats(List <Cat> cats)
    {
        string[] catInfo;

        while ((catInfo = Console.ReadLine().Split(' '))[0] != "End")
        {
            if (catInfo[0] == "StreetExtraordinaire")
            {
                Extraordinaire cat = new Extraordinaire(catInfo[1], int.Parse(catInfo[2]), catInfo[0]);
                cats.Add(cat);
            }
            else if (catInfo[0] == "Siamese")
            {
                Siamese cat = new Siamese(catInfo[1], int.Parse(catInfo[2]), catInfo[0]);
                cats.Add(cat);
            }
            else if (catInfo[0] == "Cymric")
            {
                Cymric cat = new Cymric(catInfo[1], double.Parse(catInfo[2]), catInfo[0]);
                cats.Add(cat);
            }
        }
    }
    static void Main(string[] args)
    {
        List <Cat> cats  = new List <Cat>();
        string     input = Console.ReadLine();

        while (input != "End")
        {
            string[] catInfo = input.Split();
            string   breed   = catInfo[0];
            string   name    = catInfo[1];
            Cat      newCat  = new Cat();
            switch (breed)
            {
            case "Siamese":
                newCat = new Siamese(decimal.Parse(catInfo[2]));

                break;

            case "Cymric":
                newCat = new Cymric(decimal.Parse(catInfo[2]));
                break;

            case "StreetExtraordinaire":
                newCat = new StreetExtraordinaire(decimal.Parse(catInfo[2]));
                break;
            }
            newCat.name  = name;
            newCat.breed = breed;
            cats.Add(newCat);
            input = Console.ReadLine();
        }
        string desiredCatName = Console.ReadLine();
        Cat    desiredCat     = cats.First(x => x.name == desiredCatName);

        Console.WriteLine(desiredCat);
    }
Exemple #24
0
    static void Main()
    {
        var input = Console.ReadLine();

        var cats = new List <Cat>();

        while (input != "End")
        {
            var currentInput = input.Split();

            if (currentInput[0] == "Siamese")
            {
                var siamese = new Siamese(currentInput[0], currentInput[1], int.Parse(currentInput[2]));

                cats.Add(siamese);
            }
            else if (currentInput[0] == "Cymric")
            {
                var cymric = new Cymric(currentInput[0], currentInput[1], double.Parse(currentInput[2]));
                cats.Add(cymric);
            }
            else if (currentInput[0] == "StreetExtraordinaire")
            {
                var StreetExtraordinaire = new StreetExtraordinaire(currentInput[0], currentInput[1], int.Parse(currentInput[2]));
                cats.Add(StreetExtraordinaire);
            }

            input = Console.ReadLine();
        }

        var catName = Console.ReadLine();

        var result = cats.FirstOrDefault(c => c.Name == catName);

        Console.WriteLine(result.ToString());
    }
        static void Main()
        {
            List <Cat> cats = new List <Cat>();

            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                string  breed    = input.Split(' ', StringSplitOptions.RemoveEmptyEntries)[0];
                string  name     = input.Split(' ', StringSplitOptions.RemoveEmptyEntries)[1];
                decimal specific = decimal.Parse(input.Split(' ', StringSplitOptions.RemoveEmptyEntries)[2]);

                switch (breed)
                {
                case "Siamese":
                    Siamese siamese = new Siamese(name, specific);
                    cats.Add(siamese);
                    break;

                case "Cymric":
                    Cymric cymric = new Cymric(name, specific);
                    cats.Add(cymric);
                    break;

                case "StreetExtraordinaire":
                    StreetExtraordinaire streetExtraordinaire = new StreetExtraordinaire(name, specific);
                    cats.Add(streetExtraordinaire);
                    break;
                }
            }

            string catName    = Console.ReadLine();
            var    currentCat = cats.FirstOrDefault(a => a.Name == catName);

            Console.WriteLine(currentCat);
        }
Exemple #26
0
 public void AddCymric(Cymric cymric)
 {
     cymrics.Add(cymric);
 }
Exemple #27
0
    public static void Main(string[] args)
    {
        var cats = new List <Cat>();

        while (true)
        {
            var input = Console.ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            if (input[0] == "End")
            {
                break;
            }
            var catType = input[0];
            if (catType == "Cymric")
            {
                var cymricName = input[1];
                var furLen     = double.Parse(input[2]);
                var cymric     = new Cymric(cymricName, furLen);
                cats.Add(cymric);
            }
            if (catType == "Siamese")
            {
                var siameseName = input[1];
                var earSize     = int.Parse(input[2]);
                var siamese     = new Siamese(siameseName, earSize);
                cats.Add(siamese);
            }
            if (catType == "StreetExtraordinaire")
            {
                var streetExtraordinaireName = input[1];
                var decibelsOfMeows          = int.Parse(input[2]);
                var streetExtraordinaire     = new StreetExtraordinaire(streetExtraordinaireName, decibelsOfMeows);
                cats.Add(streetExtraordinaire);
            }
        }
        var searchedName = Console.ReadLine();

        foreach (var item in cats)
        {
            try
            {
                var cymbric = (Cymric)item;
                if (cymbric.Name == searchedName)
                {
                    Console.WriteLine(cymbric.ToString());
                    continue;
                }
            }
            catch
            {
            }
            try
            {
                var siamese = (Siamese)item;
                if (siamese.Name == searchedName)
                {
                    Console.WriteLine(siamese.ToString());
                    continue;
                }
            }
            catch
            {
            }
            try
            {
                var streetCat = (StreetExtraordinaire)item;
                if (streetCat.Name == searchedName)
                {
                    Console.WriteLine(streetCat.ToString());
                    continue;
                }
            }
            catch
            {
            }
        }
    }