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

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

            var entry = PromptAction();

            if (entry == "print")
            {
                var data = PrepData(emu);
                PrintToPrinter(data);
            }
            else if (entry == "save")
            {
                var data = PrepData(emu);
                SaveToFile(data);
            }
            else
            {
            }
        }
Esempio n. 2
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");
        }
Esempio n. 3
0
        private static string[] PrepData(Emu emu)
        {
            // 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: Emu";
            data[3]  = "";
            data[4]  = "Here's the information available about emus:";
            data[5]  = "\t Animal subtype: " + emu.Subtype;
            data[6]  = "\t Diet: " + emu.Diet;
            data[7]  = "\t Movement: " + emu.Movement;
            data[8]  = "\t Reproduction method: " + emu.Reproduction;
            data[9]  = "";
            data[10] = emu.Scientific;
            data[11] = emu.Origin;

            return(data);
        }