Ejemplo n.º 1
0
        public void SendForCastration(string[] arr)
        {
            string           adoptionCenterName   = arr[1];
            string           castrationCenterName = arr[2];
            AdoptionCenter   CurrAdop             = this.AdoptionCenterlis.Where(se => se.Name == adoptionCenterName).First();
            CastrationCenter CurrCastr            = this.CastrationCentersLis.Where(se => se.Name == castrationCenterName).First();

            CurrAdop.Send4Cast(CurrCastr);
        }
Ejemplo n.º 2
0
        public void Castrate(string[] arr)
        {
            string           name       = arr[1];
            CastrationCenter CurrCenter = this.CastrationCentersLis.First(se => se.Name == name);

            foreach (var animal in CurrCenter.animals)
            {
                CurrCenter.Castrate(this.AdoptionCenterlis.Find(se => se.Name == animal.DefCenter), animal);
                this.Castrated.Add(animal.Name);
            }
            foreach (var animal in this.Castrated)
            {
                CurrCenter.animals.Remove(CurrCenter.animals.First(se => se.Name == animal));
            }
        }
Ejemplo n.º 3
0
    public void RegisterCastrationCenter(string name)
    {
        CastrationCenter castrationCenter = new CastrationCenter(name);

        castrationCenters.Add(castrationCenter);
    }
Ejemplo n.º 4
0
    public void RegisterCastrationCenter(string name)
    {
        CastrationCenter current = new CastrationCenter(name);

        this.castrationCenters[name] = current;
    }
Ejemplo n.º 5
0
        public void ProcessCommand(string input)
        {
            var command = input.Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries)
                          .ToArray();

            if (command[0] == "RegisterCleansingCenter")
            {
                var center = new CleansingCenter(command[1]);
                AvailableCentres.cleansingCenters.Add(center);
            }
            else if (command[0] == "RegisterAdoptionCenter")
            {
                var center = new AdoptionCenter(command[1]);
                AvailableCentres.adoptionCenters.Add(center);
            }
            else if (command[0] == "RegisterCastrationCenter")
            {
                var center = new CastrationCenter(command[1]);
                AvailableCentres.castrationCenters.Add(center);
            }
            else if (command[0] == "RegisterDog")
            {
                var animal = new Dog(command[1], int.Parse(command[2]), int.Parse(command[3]));
                var center = AvailableCentres.adoptionCenters.First(x => x.Name == command[4]);
                center.AdmitAnimal(animal);
            }
            else if (command[0] == "RegisterCat")
            {
                var animal = new Cat(command[1], int.Parse(command[2]), int.Parse(command[3]));
                var center = AvailableCentres.adoptionCenters.First(x => x.Name == command[4]);
                center.AdmitAnimal(animal);
            }
            else if (command[0] == "SendForCleansing")
            {
                var center = AvailableCentres.adoptionCenters.FirstOrDefault(x => x.Name == command[1]);
                center.SendForCleance(command[2]);
            }
            else if (command[0] == "SendForCastration")
            {
                var center = AvailableCentres.adoptionCenters.FirstOrDefault(x => x.Name == command[1]);

                center.SendForCastration(command[2]);
            }
            else if (command[0] == "Cleanse")
            {
                var center = AvailableCentres.cleansingCenters.FirstOrDefault(x => x.Name == command[1]);
                center.Cleanse();
            }
            else if (command[0] == "Adopt")
            {
                var center = AvailableCentres.adoptionCenters.First(x => x.Name == command[1]);
                center.Adopt();
            }
            else if (command[0] == "Castrate")
            {
                var center = AvailableCentres.castrationCenters.First(x => x.Name == command[1]);
                center.Castrate();
            }
            else if (command[0] == "CastrationStatistics")
            {
                writer.CastrationStatistics();
            }
            else
            {
                throw new IndexOutOfRangeException("Wrong command");
            }
        }
Ejemplo n.º 6
0
    public static void Execute()
    {
        while (true)
        {
            string[] commandArgs = Console.ReadLine().Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
            string   command     = commandArgs[0];
            switch (command)
            {
            case "RegisterCastrationCenter":
                string centerName = commandArgs[1];
                castrationCenters.Add(new CastrationCenter(centerName));
                break;

            case "RegisterCleansingCenter":
                centerName = commandArgs[1];
                cleansingCenters.Add(new CleansingCenter(centerName));
                break;

            case "RegisterAdoptionCenter":
                centerName = commandArgs[1];
                adoptionCenters.Add(new AdoptionCenter(centerName));
                break;

            case "RegisterDog":
                IAnimal dog = null;
                try
                {
                    dog = AnimalFactory.CreateAnimal("Dog", commandArgs[1], commandArgs[2], commandArgs[3]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
                string adoadoptionCenterName = commandArgs[4];

                AdoptionCenter center = adoptionCenters.FirstOrDefault(c => c.Name == adoadoptionCenterName);

                center.AddAnimal(dog);

                break;

            case "RegisterCat":
                IAnimal cat = null;
                try
                {
                    cat = AnimalFactory.CreateAnimal("Cat", commandArgs[1], commandArgs[2], commandArgs[3]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                adoadoptionCenterName = commandArgs[4];

                center = adoptionCenters.FirstOrDefault(c => c.Name == adoadoptionCenterName);

                center.AddAnimal(cat);
                break;

            case "SendForCleansing":
                adoadoptionCenterName = commandArgs[1];
                string cleansingCenterName = commandArgs[2];

                AdoptionCenter  adoadoptionCenter = adoptionCenters.FirstOrDefault(c => c.Name == adoadoptionCenterName);
                CleansingCenter cleansingCenter   = cleansingCenters.FirstOrDefault(c => c.Name == cleansingCenterName);

                cleansingCenter.AddAnimalsFromAdoptionCenter(adoadoptionCenter.SendForCleansing());
                break;

            case "SendForCastration":
                adoadoptionCenterName = commandArgs[1];
                string castrationCenterName = commandArgs[2];

                adoadoptionCenter = adoptionCenters.FirstOrDefault(c => c.Name == adoadoptionCenterName);

                CastrationCenter castrationCenter = castrationCenters.FirstOrDefault(c => c.Name == castrationCenterName);

                castrationCenter.AddAnimalsFromAdoptionCenter(adoadoptionCenter.SendForCastration());
                break;

            case "Cleanse":
                cleansingCenterName = commandArgs[1];
                cleansingCenter     = cleansingCenters.FirstOrDefault(c => c.Name == cleansingCenterName);

                var centerAndAnimals = cleansingCenter.Cleanse();

                foreach (var pair in centerAndAnimals)
                {
                    adoadoptionCenterName = pair.Key;
                    adoadoptionCenter     = adoptionCenters.FirstOrDefault(c => c.Name == adoadoptionCenterName);

                    adoadoptionCenter.AddAnimals(pair.Value);
                }
                break;

            case "Castrate":
                castrationCenterName = commandArgs[1];
                castrationCenter     = castrationCenters.FirstOrDefault(c => c.Name == castrationCenterName);

                centerAndAnimals = castrationCenter.Castrate();

                foreach (var pair in centerAndAnimals)
                {
                    adoadoptionCenterName = pair.Key;
                    adoadoptionCenter     = adoptionCenters.FirstOrDefault(c => c.Name == adoadoptionCenterName);

                    adoadoptionCenter.AddAnimals(pair.Value);
                }
                break;

            case "Adopt":
                adoadoptionCenterName = commandArgs[1];
                adoadoptionCenter     = adoptionCenters.FirstOrDefault(c => c.Name == adoadoptionCenterName);

                adoadoptionCenter.Adopt();
                break;

            case "CastrationStatistics":
                StringBuilder sb = new StringBuilder();

                sb.Append($"Paw Inc. Regular Castration Statistics{Environment.NewLine}");
                sb.Append($"Castration Centers: {castrationCenters.Count}{Environment.NewLine}");

                string castratedAnimals = CastrationCenter.CastratedAnimals.Count == 0 ? "None" : string.Join(", ", CastrationCenter.CastratedAnimals.OrderBy(a => a.Name));
                sb.Append($"Castrated Animals: {castratedAnimals}");

                Console.WriteLine(sb.ToString());
                break;

            case "Paw Paw Pawah":
                sb = new StringBuilder();
                sb.Append($"Paw Incorporative Regular Statistics{Environment.NewLine}");

                sb.Append($"Adoption Centers: {adoptionCenters.Count}{Environment.NewLine}");
                sb.Append($"Cleansing Centers: {cleansingCenters.Count}{Environment.NewLine}");

                string adoptedAnimals = AdoptionCenter.AdoptedAnimals.Count == 0 ? "None" : string.Join(", ", AdoptionCenter.AdoptedAnimals.OrderBy(a => a.Name));
                sb.Append($"Adopted Animals: {adoptedAnimals}{Environment.NewLine}");

                string cleansedAnimals = CleansingCenter.CleansedAnimals.Count == 0 ? "None" : string.Join(", ", CleansingCenter.CleansedAnimals.OrderBy(a => a.Name));
                sb.Append($"Cleansed Animals: {cleansedAnimals}{Environment.NewLine}");

                int amountOfAnimalsWaitingForAdoption = adoptionCenters.Sum(a => a.AnimalsAwaitingAdoption());
                sb.Append($"Animals Awaiting Adoption: {amountOfAnimalsWaitingForAdoption}{Environment.NewLine}");

                int amountOfAnimalsWaitingForCleansing = cleansingCenters.Sum(a => a.AnimalsAwaitingCleansing());
                sb.Append($"Animals Awaiting Cleansing: {amountOfAnimalsWaitingForCleansing}");

                Console.WriteLine(sb.ToString());
                return;
            }
        }
    }
Ejemplo n.º 7
0
 public void SendForCastration(CastrationCenter castrationCenter)
 {
     (castrationCenter.StoredAnimals as List <Animal>).AddRange(this.StoredAnimals);
     (this.StoredAnimals as List <Animal>).Clear();
 }
Ejemplo n.º 8
0
    public static void Start()
    {
        var    adoptet           = new List <string>();
        var    adoptetCentres    = new List <AdoptionCenter>();
        var    clinned           = new List <string>();
        var    clinnedCeneters   = new List <CleansingCenter>();
        var    castrationCenter  = new List <CastrationCenter>();
        var    castrationAnimals = new List <string>();
        string inputLine;

        while ((inputLine = Console.ReadLine()) != "Paw Paw Pawah")
        {
            var    command = inputLine.Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
            var    cmdArg  = command[0];
            string name    = null;
            if (command.Length > 1)
            {
                name = command[1];
            }
            switch (cmdArg)
            {
            case "RegisterCleansingCenter": var clining = new CleansingCenter(name);
                clinnedCeneters.Add(clining);
                break;

            case "RegisterAdoptionCenter": var adop = new AdoptionCenter(name);
                adoptetCentres.Add(adop);
                break;

            case "RegisterDog": var dog = new Dog(name, int.Parse(command[2]), int.Parse(command[3]), command[4]);
                adoptetCentres.First(n => n.Name == command[4]).AddAnimal(dog);
                break;

            case "RegisterCat":
                var cat = new Cat(name, int.Parse(command[2]), int.Parse(command[3]), command[4]);
                adoptetCentres.First(n => n.Name == command[4]).AddAnimal(cat);
                break;

            case "SendForCleansing":
                var forClining = adoptetCentres.First(c => c.Name == name);
                var cliniin    = clinnedCeneters.First(c => c.Name == command[2]);
                cliniin.AddForClining(forClining.Animals);
                break;

            case "Cleanse":
                var clin = clinnedCeneters.First(c => c.Name == name);
                foreach (var clinAnimal in clin.Animals)
                {
                    clinned.Add(clinAnimal.Name);
                }
                clin.CliningAnimal();
                break;

            case "Adopt":
                var adopt = adoptetCentres.FirstOrDefault(c => c.Name == name);
                if (adopt != null)
                {
                    foreach (var clinAnimal in adopt.Animals)
                    {
                        if (clinAnimal.Status)
                        {
                            adoptet.Add(clinAnimal.Name);
                        }
                    }
                }
                adopt.Adopt(adoptet);
                break;

            case "RegisterCastrationCenter": var center = new CastrationCenter(name);
                castrationCenter.Add(center);
                break;

            case "SendForCastration": var adoptetCenter = adoptetCentres.FirstOrDefault(c => c.Name == name);
                var centerCast = castrationCenter.FirstOrDefault(c => c.Name == command[2]);
                if (adoptetCenter != null && centerCast != null)
                {
                    centerCast.AddAnimalCastration(adoptetCenter.Animals);
                }
                break;

            case "Castrate": var cst = castrationCenter.First(c => c.Name == name);
                foreach (var cstAnimal in cst.Animals)
                {
                    castrationAnimals.Add(cstAnimal.Name);
                }
                cst.Castration();
                break;

            case "CastrationStatistics": var sbb = new StringBuilder();
                sbb.AppendLine($"Paw Inc. Regular Castration Statistics")
                .AppendLine($"Castration Centers: {castrationCenter.Count}");
                if (castrationAnimals.Count != 0)
                {
                    sbb.AppendLine($"Castrated Animals: {string.Join(", ", castrationAnimals.OrderBy(x => x))}");
                }
                else
                {
                    sbb.AppendLine($"Castrated Animals: None");
                }
                Console.WriteLine(sbb.ToString().Trim());
                break;
            }
        }

        var sb = new StringBuilder();

        sb.AppendLine($"Paw Incorporative Regular Statistics")
        .AppendLine($"Adoption Centers: {adoptetCentres.Count}")
        .AppendLine($"Cleansing Centers: {clinnedCeneters.Count}");
        if (adoptet.Count == 0)
        {
            sb.AppendLine($"Adopted Animals: None");
        }
        else
        {
            sb.AppendLine($"Adopted Animals: {string.Join(", ", adoptet.OrderBy(x => x))}");
        }
        if (clinned.Count == 0)
        {
            sb.AppendLine($"Cleansed Animals: None");
        }
        else
        {
            sb.AppendLine($"Cleansed Animals: {string.Join(", ", clinned.OrderBy(x=>x))}");
        }
        int count = 0;

        foreach (var VARIABLE in adoptetCentres.SelectMany(x => x.Animals))
        {
            if (VARIABLE.Status)
            {
                count++;
            }
        }
        sb.AppendLine($"Animals Awaiting Adoption: {count}");
        int coont = 0;

        foreach (var VARIABLE in clinnedCeneters.SelectMany(x => x.Animals))
        {
            if (!VARIABLE.Status)
            {
                coont++;
            }
        }
        sb.AppendLine($"Animals Awaiting Cleansing: {coont}");
        var result = sb.ToString().Trim();

        Console.WriteLine(result);
    }