示例#1
0
        private Animal CreateReptile()
        {
            // method to read Reptile specific inputs
            Animal animal = null;

            bool livesInWater = true;

            if (textBoxTeeth.Text == "YES")
            {
                livesInWater = true;
            }
            else if (textBoxTeeth.Text == "NO")
            {
                livesInWater = false;
            }


            double weight = 0.0;

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

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

            animal = Reptile.CreateReptile(species, weight, livesInWater);

            if (species == ReptileSpecies.Snake)
            {
                ((Snake)animal).Color = LabelSpeciesProperty.Text;
            }

            else if (species == ReptileSpecies.Lizard)
            {
                ((Lizard)animal).Color = LabelSpeciesProperty.Text;
            }
            else if (species == ReptileSpecies.Turtle)
            {
                ((Turtle)animal).Color = LabelSpeciesProperty.Text;
            }
            return(animal);
        }
示例#2
0
        /// <summary>
        /// CreateReptile: Method that will be used to created different reptile objects
        /// </summary>
        public static Reptile CreateReptile(ReptileSpecies species, double weight, bool livesInWater)
        {
            Reptile reptile = null;

            switch (species)
            {
            case ReptileSpecies.Snake:
                reptile = new Snake(weight, livesInWater);
                break;

            case ReptileSpecies.Lizard:
                reptile = new Lizard(weight, livesInWater);
                break;

            case ReptileSpecies.Turtle:
                reptile = new Turtle(weight, livesInWater);
                break;
            }
            return(reptile);
        }