Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Cat        cat        = new Cat();
            Dog        dog        = new Dog();
            Cow        cow        = new Cow();
            YellowBird yellowBird = new YellowBird();
            GoldFish   goldFish   = new GoldFish();
            Frog       frog       = new Frog();

            cat.MakeNoise();
            cat.Walk();
            cat.Run();

            dog.MakeNoise();
            dog.Walk();
            dog.Run();

            yellowBird.MakeNoise();
            yellowBird.Fly();

            goldFish.Swim();

            frog.Swim();
            frog.Walk();

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                Random gen = new Random();


                if (radDog.Checked)
                {
                    Gender randomGender = (Gender)gen.Next((int)Gender.Male, (int)Gender.Unknown + 1);

                    Dog shep = new Dog();

                    shep.name   = Interaction.InputBox("Enter your dog's name.", "Name");
                    shep.color  = Interaction.InputBox("Enter your dog's color.", "Color");
                    shep.weight = Convert.ToDouble(Interaction.InputBox("Enter your dog's weight.", "Weight"));
                    shep.gender = randomGender;

                    lblOut.Text += shep.ToString();
                    shep.MakeNoise();
                }
                else if (radCat.Checked)
                {
                    Cat mittens = new Cat();

                    Gender randomGender = (Gender)gen.Next((int)Gender.Male, (int)Gender.Unknown + 1);

                    mittens.name   = Interaction.InputBox("Enter your cat's name.", "Name");
                    mittens.color  = Interaction.InputBox("Enter your cat's color.", "Color");
                    mittens.weight = Convert.ToDouble(Interaction.InputBox("Enter your cat's weight.", "Weight"));
                    mittens.gender = randomGender;

                    lblOut.Text += mittens.ToString();
                    mittens.MakeNoise();
                }
                else
                {
                    Bird tweetie = new Bird();

                    Gender randomGender = (Gender)gen.Next((int)Gender.Male, (int)Gender.Unknown + 1);

                    tweetie.name   = Interaction.InputBox("Enter your bird's name.", "Name");
                    tweetie.color  = Interaction.InputBox("Enter your bird's color.", "Color");
                    tweetie.weight = Convert.ToDouble(Interaction.InputBox("Enter your bird's weight.", "Weight"));
                    tweetie.gender = randomGender;

                    lblOut.Text += tweetie.ToString();
                    tweetie.MakeNoise();
                }
            }

            catch
            {
                lblOut.Text = "Please enter valid values.";
            }
        }