Beispiel #1
0
 static void PrintAnimalsToConsole(AnimalsContainer animals)
 {
     for (int i = 0; i < animals.Count; i++)
     {
         Console.WriteLine("Nr {0, 2}: {1}", (i + 1), animals.GetAnimal(i).ToString());
     }
 }
Beispiel #2
0
        private AnimalsContainer FilterByBreed(AnimalsContainer animals, string breed)
        {
            AnimalsContainer filteredAnimals = new AnimalsContainer(Program.MaxNumberOfAnimals);

            for (int i = 0; i < animals.Count; i++)
            {
                if (animals.GetAnimal(i).Breed == breed)
                {
                    filteredAnimals.AddAnimal(animals.GetAnimal(i));
                }
            }
            return(filteredAnimals);
        }
Beispiel #3
0
 private void GetBreeds(AnimalsContainer animals, out string[] breeds, out int breedCount)
 {
     breeds     = new string[MaxNumberOfBreeds];
     breedCount = 0;
     for (int i = 0; i < animals.Count; i++)
     {
         string breed = animals.GetAnimal(i).Breed;
         if (!breeds.Contains(breed))
         {
             breeds[breedCount++] = breed;
         }
     }
 }
Beispiel #4
0
        private int CountAggressive(AnimalsContainer animals)
        {
            int counter = 0;

            for (int i = 0; i < animals.Count; i++)
            {
                Dog dog = animals.GetAnimal(i) as Dog;
                if (dog != null && dog.Aggressive)
                {
                    counter++;
                }
            }
            return(counter);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Program p = new Program();

            Branch[] branches = new Branch[NumberOfBranches];
            branches[0] = new Branch("Kaunas");
            branches[1] = new Branch("Vilnius");
            branches[2] = new Branch("Šiauliai");
            string[] filePaths = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.csv");
            foreach (string path in filePaths)
            {
                bool rado = p.ReadAnimalData(path, branches);
                if (rado == false)
                {
                    Console.WriteLine("Neatpažintas failo {0} miestas", path);
                }
            }
            Console.WriteLine("Kaune užregistruoti šunys:");
            PrintAnimalsToConsole(branches[0].Dogs);

            Console.WriteLine();
            Console.WriteLine("Agresyvūs Kauno šunys: {0}", p.CountAggressive(branches[0].Dogs));
            Console.WriteLine("Agresyvūs Vilniaus šunys: {0}", p.CountAggressive(branches[1].Dogs));

            AnimalsContainer kaunasDogs  = branches[0].Dogs;
            AnimalsContainer vilniusCats = branches[1].Cats;

            Console.WriteLine("Populiariausia šunų veislė Kaune: {0}", p.GetMostPopularBreed(kaunasDogs));
            Console.WriteLine("Populiariausia kačių veislė Vilniuje: {0}", p.GetMostPopularBreed(vilniusCats));
            Console.WriteLine();

            Console.WriteLine("Surūšiuotas visų filialų šunų sąrašas:");
            Console.WriteLine();
            AnimalsContainer allDogs = new AnimalsContainer(Program.MaxNumberOfAnimals * Program.NumberOfBranches);

            for (int i = 0; i < NumberOfBranches; i++)
            {
                for (int j = 0; j < branches[i].Dogs.Count; j++)
                {
                    allDogs.AddAnimal(branches[i].Dogs.GetAnimal(j));
                }
            }
            allDogs.SortAnimals();
            PrintAnimalsToConsole(allDogs);
        }
Beispiel #6
0
        private string GetMostPopularBreed(AnimalsContainer animals)
        {
            String popular    = "not found";
            int    count      = 0;
            int    breedCount = 0;

            string[] breeds;
            GetBreeds(animals, out breeds, out breedCount);
            for (int i = 0; i < breedCount; i++)
            {
                AnimalsContainer filteredAnimals = FilterByBreed(animals, breeds[i]);
                if (filteredAnimals.Count > count)
                {
                    popular = breeds[i];
                    count   = filteredAnimals.Count;
                }
            }
            return(popular);
        }
Beispiel #7
0
 public Branch(string town)
 {
     Town = town;
     Dogs = new AnimalsContainer(Program.MaxNumberOfAnimals);
     Cats = new AnimalsContainer(Program.MaxNumberOfAnimals);
 }