예제 #1
0
        // Function to add element to the stack.
        public static void AddElem(ref Stack <AbstrState> stack)
        {
            Console.Clear();

            // Objects that will be added.
            Republic republicCongo      = new Republic("The Republic of the Congo", "Denis Sassou Nguesso", 5125821, 58, "Africa", 7, 72, 6);
            Monarchy monarchyBelgium    = new Monarchy("Belgium", "Philippe", 11358357, 189, "Europe", "The House of Saxe-Coburg and Gotha");
            Kingdom  kingdomSaudiArabia = new Kingdom("The Kingdom of Saudi Arabia", "Salman", 33000000, 87, "Asia", "The Sudairi Seven");

            Console.Clear();

            Console.WriteLine(@"Choose the class of the adding object
1. Republic.
2. Monarchy.
3. Kingdom.
4. Back.");
            // Getting the class of the adding object.
            int choice = Program.ChoiceInput(4);

            switch (choice)
            {
            case 1:
                stack.Push(republicCongo);
                Console.WriteLine("The Republic of the Congo has been successfully added to the stack!\nPress ENTER to go back.");
                Console.ReadLine();
                break;

            case 2:
                stack.Push(monarchyBelgium);
                Console.WriteLine("Belgium has been successfully added to the stack!\nPress ENTER to go back.");
                Console.ReadLine();
                break;

            case 3:
                stack.Push(kingdomSaudiArabia);
                Console.WriteLine("The Kingdom of Saudi Arabia has been successfully added to the stack!\nPress ENTER to go back.");
                Console.ReadLine();
                break;

            case 4:
                break;
            }
        }
예제 #2
0
        public static void Demostrate()
        {
            // Republic class.
            //Republic republicCongo = new Republic("The Republic of the Congo", "Denis Sassou Nguesso", 5125821, 58, "Africa", 7, 72, 6);
            Republic republicCzech     = new Republic("The Czech Republic", "Milos Zeman", 10610947, 25, "Europe", 10, 200, 4);
            Republic republicTurkey    = new Republic("The Republic of Turkey", "Recep Tayyip Erdogan", 80810525, 95, "Asia", 5, 550, 4);
            Republic republicArgentina = new Republic("The Argentine Republic", "Mauricio Macri", 43847430, 102, "America", 4, 329, 2);
            Republic republicNauru     = new Republic("The Republic of Nauru", "Baron Waqa", 10084, 50, "Oceania", 3, 19, 3);

            // Monarchy class.
            //Monarchy monarchyBelgium = new Monarchy("Belgium", "Philippe", 11358357, 189, "Europe", "The House of Saxe-Coburg and Gotha");
            Monarchy monarchyAustralia = new Monarchy("Australia", "Elizabeth II", 24067700, 117, "Oceania", "House of Windsor");
            Monarchy monarchyJamaica   = new Monarchy("Jamaica", "Elizabeth II", 43847430, 56, "America", "House of Windsor");

            // Kingdom class.
            //Kingdom kingdomSaudiArabia = new Kingdom("The Kingdom of Saudi Arabia", "Salman", 33000000, 87, "Asia", "The Sudairi Seven");
            Kingdom kingdomMarocco = new Kingdom("The Kingdom of Morocco", "Mohammed VI", 33848242, 62, "Africa", "The Alaouite dynasty");

            // Creating new arraylist.
            ArrayList arrayList = new ArrayList
            {
                //republicCongo,
                republicCzech,
                republicTurkey,
                republicArgentina,
                republicNauru,
                //monarchyBelgium,
                monarchyAustralia,
                monarchyJamaica,
                //kingdomSaudiArabia,
                kingdomMarocco,
            };

            int choice = -1;

            do
            {
                Console.Clear();
                // Showing the created arraylist.
                Console.WriteLine("CURRENT ARRAYLIST:");
                foreach (AbstrState state in arrayList)
                {
                    state.Show();
                }

                Console.WriteLine(@"Choose one of the options:
1. Add element.
2. Delete element.
3. Show the number of republics.
4. Show all the monarchy states.
5. Show all the African states.
6. Clone the arraylist.
7. Sort the arraylist.
8. Search element.
9. Back.");

                // Getting the number of the chosen option.
                choice = Program.ChoiceInput(9);

                switch (choice)
                {
                case 1:
                    AddElem(ref arrayList);
                    break;

                case 2:
                    DelElem(ref arrayList);
                    break;

                case 3:
                    ShowNumOfRep(arrayList);
                    break;

                case 4:
                    ShowMon(arrayList);
                    break;

                case 5:
                    ShowAfrSt(arrayList);
                    break;

                case 6:
                    CloneArrayList(arrayList);
                    break;

                case 7:
                    SortArrayList(ref arrayList);
                    break;

                case 8:
                    BinarySearchArrL(arrayList);
                    break;
                }
            } while (choice != 9);

            //Console.ReadLine();
        }