Ejemplo n.º 1
0
        /// <summary>
        /// CreateBird: Method that will be used to create different bird objects
        /// </summary>
        public static Bird CreateBird(BirdsSpecies species, double wingSpan, double lengthOfBeak)
        {
            Bird bird = null;

            switch (species)
            {
            case BirdsSpecies.Dove:
                bird = new Dove(wingSpan, lengthOfBeak);
                break;

            case BirdsSpecies.Pigeon:
                bird = new Pigeon(wingSpan, lengthOfBeak);
                break;

            case BirdsSpecies.Eagle:
                bird = new Eagle(wingSpan, lengthOfBeak);
                break;
            }
            return(bird);
        }
Ejemplo n.º 2
0
        private Animal CreateBird()
        {
            // method to read Bird specific inputs

            Animal animal = null;

            double wingSpan = 0;

            if (!double.TryParse(textBoxTeeth.Text, out wingSpan))
            {
                MessageBox.Show("Please give a valid value for a wingspan!");
            }
            double lengthOfBeak = 0;

            if (!double.TryParse(textBoxTail.Text, out lengthOfBeak))
            {
                MessageBox.Show("Please give a valid value for length of a beak!");
            }

            BirdsSpecies species = (BirdsSpecies)Enum.Parse(typeof(BirdsSpecies), listBoxAnimal.Text);

            animal = Bird.CreateBird(species, wingSpan, lengthOfBeak);

            if (species == BirdsSpecies.Dove)
            {
                ((Dove)animal).Color = textBoxAnimalSpec.Text;
            }

            else if (species == BirdsSpecies.Pigeon)
            {
                ((Pigeon)animal).Color = textBoxAnimalSpec.Text;
            }

            else if (species == BirdsSpecies.Eagle)
            {
                ((Eagle)animal).Color = textBoxAnimalSpec.Text;
            }

            return(animal);
        }