Exemple #1
0
        public void AnimalChoice(Kangaroo roo)
        {
            // Info about kangaroos, then prompting for action on the data.
            Console.WriteLine("You've chosen to see information about kangaroos!");
            Console.WriteLine("Here's the information I have about kangaroos:{0}", Environment.NewLine);

            Console.WriteLine("The kangaroo is a {0}, its diet is {1}, it moves by {2} and it reproduces by {3}",
                              roo.Subtype, roo.Diet, roo.Movement, roo.Reproduction);
            roo.Science();
            roo.Originate();

            var entry = PromptAction();

            if (entry == "print")
            {
                var data = PrepData(roo);
                PrintToPrinter(data);
            }
            else if (entry == "save")
            {
                var data = PrepData(roo);
                SaveToFile(data);
            }
            else
            {
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates aniamls for the factory.
        /// </summary>
        /// <param name="type"> The type of animal that will be created.</param>
        /// <param name="name"> The name of the animal.</param>
        /// <param name="age"> The age of the animal.</param>
        /// <param name="weight"> The weight of the animal.</param>
        /// <param name="gender"> The gender of the animal.</param>
        public static Animal CreateAnimal(AnimalType type, string name, int age, double weight, Gender gender)
        {
            Animal result = null;

            switch (type)
            {
            case AnimalType.Chimpanzee:
                result = new Chimpanzee(name, age, weight, gender);

                break;

            case AnimalType.Dingo:
                result = new Dingo(name, age, weight, gender);

                break;

            case AnimalType.Eagle:
                result = new Eagle(name, age, weight, gender);

                break;

            case AnimalType.Hummingbird:
                result = new Hummingbird(name, age, weight, gender);

                break;

            case AnimalType.Kangaroo:
                result = new Kangaroo(name, age, weight, gender);

                break;

            case AnimalType.Ostrich:
                result = new Ostrich(name, age, weight, gender);

                break;

            case AnimalType.Platypus:
                result = new Platypus(name, age, weight, gender);

                break;

            case AnimalType.Shark:
                result = new Shark(name, age, weight, gender);

                break;

            case AnimalType.Squirrel:
                result = new Squirrel(name, age, weight, gender);

                break;

            default:
                break;
            }

            return(result);
        }
Exemple #3
0
        public static void Main()
        {
            // Creating an instance of the program due to static vs non-static method mayhem in the errors. Gah...
            Program p = new Program();

            // Creating a list so the database can be extended to many more animals if desired
            List <string> animals = new List <string>();

            animals.Add("emu");
            animals.Add("kangaroo");

            // Time to say hello to the user
            Intro();

            // While loop to prompt for user input until user elects to quit,
            // will only accept valid responses and will loop until valid response received.
            while (true)
            {
                var response = Prompt(animals).ToLower();

                // Verifying user input and taking appropriate action
                if (animals.Contains(response))
                {
                    // I would only need one if/else statement here for the two items I need to worry about,
                    // but this wouldn't allow me to add more in future - so if/else-if/else it is.
                    if (response == animals[0])
                    {
                        Emu emu = new Emu();
                        p.AnimalChoice(emu);
                    }
                    else if (response == animals[1])
                    {
                        Kangaroo roo = new Kangaroo();
                        p.AnimalChoice(roo);
                    }
                    else
                    {
                    }
                }
                else if (response == "quit")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("That's not a valid entry, please try again.");
                }
            }

            Console.WriteLine("Goodbye");
        }
Exemple #4
0
        private static string[] PrepData(Kangaroo roo)
        {
            // Prepping the data for printing or saving so that all that needs to be handled by those methods is a string array.
            string[] data = new string[12];

            data[0]  = "Animal Database";
            data[1]  = "";
            data[2]  = "Animal selected: Kangaroo";
            data[3]  = "";
            data[4]  = "Here's the information available about kangaroos:";
            data[5]  = "\t Animal subtype: " + roo.Subtype;
            data[6]  = "\t Diet: " + roo.Diet;
            data[7]  = "\t Movement: " + roo.Movement;
            data[8]  = "\t Reproduction method: " + roo.Reproduction;
            data[9]  = "";
            data[10] = roo.Scientific;
            data[11] = roo.Origin;

            return(data);
        }
Exemple #5
0
        /// <summary>
        /// Creates an animal.
        /// </summary>
        /// <param name="type">The type of animal.</param>
        /// <param name="name">The name of the animal.</param>
        /// <param name="age">The age of the animal.</param>
        /// <param name="weight">The weight of the animal.</param>
        /// <param name="gender">The gender of the animal.</param>
        /// <returns>Returns an animal.</returns>
        public static Animal CreateAnimal(AnimalType type, string name, int age, double weight, Gender gender)
        {
            Animal animal = null;

            switch (type)
            {
            case AnimalType.Chimpanzee:

                // Create Chewy the chimpanzee.
                animal = new Chimpanzee(name, age, weight, gender);

                break;

            case AnimalType.Dingo:

                // Create Dolly the dingo.
                animal = new Dingo(name, age, weight, gender);

                // Create Dixie the dingo.
                animal = new Dingo(name, age, weight, gender);

                break;

            case AnimalType.Eagle:
                // Create Edgar the eagle..
                animal = new Eagle(name, age, weight, gender);

                break;

            case AnimalType.Hummingbird:
                // Create Harold.
                animal = new Hummingbird(name, age, weight, gender);

                break;

            case AnimalType.Kangaroo:
                // Create Khan the kangaroo.
                animal = new Kangaroo(name, age, weight, gender);

                break;

            case AnimalType.Ostrich:
                // Create Ozzie the ostrich.
                animal = new Ostrich(name, age, weight, gender);

                break;

            case AnimalType.Platypus:
                // Create Patty.
                animal = new Platypus(name, age, weight, gender);

                break;

            case AnimalType.Shark:
                // Creates Sasha the shark.
                animal = new Shark(name, age, weight, gender);

                break;

            case AnimalType.Squirrel:
                // Create Sonny the squirrel.
                animal = new Squirrel(name, age, weight, gender);

                break;
            }

            return(animal);
        }