예제 #1
0
        public void WelcomeAction()
        {
            List <Country> myCountries = new List <Country>()
            {
                new Country("United States of America", Continents.NorthAmerica, (new List <string>()
                {
                    "Red", "White", "Blue"
                })),
                new Country("Italy", Continents.Europe, (new List <string>()
                {
                    "Green", "White", "Red"
                })),
                new Country("Lebanon", Continents.Asia, (new List <string>()
                {
                    "Red", "White", "Green"
                })),
                new Country("Belgium", Continents.Europe, (new List <string>()
                {
                    "Black", "Yellow", "Red"
                })),
                new Country("Venezuela", Continents.SouthAmerica, (new List <string>()
                {
                    "Yellow", "Blue", "Red"
                })),
                new Country("Madagascar", Continents.Africa, (new List <string>()
                {
                    "White", "Red", "Green"
                })),
                new Country("Dominican Republic", Continents.NorthAmerica, (new List <string>()
                {
                    "Red", "White", "Blue"
                })),
            };

            CountryDb = myCountries;

            bool cont = true;

            while (cont)
            {
                CountryListView view = new CountryListView(CountryDb);
                Console.WriteLine($"Hello, welcome to the country app. Please select a country from the following list: ");
                Console.WriteLine();
                view.Display();
                Console.WriteLine();
                Console.Write($"Please select a country by index (0 - {CountryDb.Count - 1}): ");
                int index = CheckNumber(Console.ReadLine(), true, (CountryDb.Count - 1));

                CountryAction(CountryDb[index]);

                Console.Write("Would you like to learn about another country? Enter y/n: ");
                string input = CheckDecision(Console.ReadLine());
                Console.WriteLine();
                if (input == "n")
                {
                    cont = false;
                }
            }
        }
예제 #2
0
        public void WelcomeAction()
        {
            bool RunProgram = true;

            while (RunProgram)
            {
                CountryListView cListView = new CountryListView(_countryDb);
                Console.WriteLine("Hello, welcome to the country app.  Please select a country from the following list:");
                cListView.Display();
                int choice = 0;
                try
                {
                    choice = int.Parse(Console.ReadLine());
                    if (choice <= 0 || choice > _countryDb.Count)
                    {
                        Console.WriteLine("Please choose a number on the list");
                        continue;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("That was not a valid entry");
                    continue;
                }
                Console.WriteLine();
                CountryAction(_countryDb[choice - 1]);
                Console.WriteLine();
                Console.WriteLine("Would you like to learn about another country? y/n");

                while (true)
                {
                    string yesno = Console.ReadLine().ToLower().Trim();
                    if (yesno == "y")
                    {
                        Console.Clear();
                        break;
                    }
                    else if (yesno == "n")
                    {
                        Console.WriteLine("Have a good day.");
                        RunProgram = false;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("That was an invalid entry.");
                    }
                }
            }
        }