Esempio n. 1
0
        static void Main(string[] args)
        {
            //Create a new droid collection and set the size of it to 100.
            IDroidCollection droidCollection = new DroidCollection(100);
            //Create a user interface and pass the droidCollection into it as a dependency
            UserInterface userInterface = new UserInterface(droidCollection);

            //Display the main greeting for the program
            userInterface.DisplayGreeting();
            //Display the main menu for the program
            userInterface.DisplayMainMenu();
            //Get the choice that the user makes
            int choice = userInterface.GetMenuChoice();

            //*****************
            //Hard coded Droids
            //*****************
            //Todo, change to droid stack
            droidCollection.Add("Quadranium", "Protocol", "Gold", 10);
            droidCollection.Add("Vanadium", "Astromech", "Silver", true, true, false, true, 3);
            droidCollection.Add("Quadranium", "Utility", "Silver", false, false, true);
            droidCollection.Add("Carbonite", "Janitor", "Bronze", true, false, true, true, true);
            droidCollection.Add("Vanadium", "Janitor", "Silver", false, true, false, false, false);
            droidCollection.Add("Carbonite", "Protocol", "Bronze", 6);
            droidCollection.Add("Carbonite", "Utility", "Gold", true, true, true);
            droidCollection.Add("Quadranium", "Astromech", "Gold", false, false, false, false, 10);
            droidCollection.Add("Quadranium", "Janitor", "Gold", true, true, true, true, true);
            droidCollection.Add("Vanadium", "Protocol", "Silver", 13);
            droidCollection.Add("Carbonite", "Astromech", "Gold", false, true, false, true, 7);
            droidCollection.Add("Vanadium", "Utility", "Silver", true, false, true);


            //While the choice is not equal to 5, continue to do work with the program
            while (choice != 5)
            {
                //Test which choice was made
                switch (choice)
                {
                //Choose to create a droid
                case 1:
                    userInterface.CreateDroid();
                    break;

                //Choose to Print the droid
                case 2:
                    userInterface.PrintDroidList();
                    break;

                //****************
                //New Menu Options
                //****************

                //Choose to Categorize by Model
                case 3:
                    droidCollection.CategorizeModels();
                    userInterface.Display("Categorized Successfully");
                    break;

                //Choose to Sort total cost
                case 4:
                    droidCollection.MergeSort();
                    userInterface.Display("Merge Sort Successful");
                    break;
                }
                //Re-display the menu, and re-prompt for the choice
                userInterface.DisplayMainMenu();
                choice = userInterface.GetMenuChoice();
            }
        }
Esempio n. 2
0
        //main menu used to start the program
        public void StartMenu()
        {
            while (DSelect != 1 || DSelect != 2 || DSelect != 3 || DSelect != 4 || DSelect != 5)
            {
                Console.WriteLine("Project # 3");
                Console.WriteLine("-------------------------");
                Console.WriteLine("1 - Add a Droid");
                Console.WriteLine("2 - Sort Droids by Model");
                Console.WriteLine("3 - Sort Droids by Total Cost");
                Console.WriteLine("4 - Print List of droids");
                Console.WriteLine("5 - Exit");
                Console.Write("");

                try
                {
                    DSelect = int.Parse(Console.ReadLine());
                    Console.WriteLine();

                    //adds droid
                    if (DSelect == 1)
                    {
                        AddDroid();
                    }

                    //sorts droids by model
                    if (DSelect == 2)
                    {
                        try
                        {   //calls bucketsort
                            droidCollection.BucketSort();
                            Console.WriteLine("Droids sorted by Model Press 4 to view list");
                            Console.WriteLine();
                        }
                        catch
                        {
                            //catch errors
                            Console.WriteLine("Error Sort failed");
                        }
                    }

                    //sorts droids by price
                    if (DSelect == 3)
                    {
                        try
                        {
                            //calls merge sort
                            droidCollection.MergeSort();
                            Console.WriteLine("Droids sorted by Price Press 4 to view lsit");
                            Console.WriteLine();
                        }
                        catch
                        {
                            //catch errors
                            Console.WriteLine("Error Sort failed");
                        }
                    }

                    //prints list of droids
                    if (DSelect == 4)
                    {
                        PrintList();
                    }

                    //exits program
                    if (DSelect == 5)
                    {
                        Environment.Exit(0);
                    }
                }
                //catch invalid input
                catch
                {
                    Console.WriteLine();
                    Console.WriteLine("Error: Please make a proper selection");
                }
            }
        }
        //*********************MAIN MENU METHOD**************************//
        public void MainMenu()
        {
            Console.WriteLine("Welcome to the Jawas on Tatooine Droid Program\n");



            AddDummyData(); //Call method to add hard-coded dummy data to DroidCollection

            while (menuSelection != 1 || menuSelection != 2 || menuSelection != 3 || menuSelection != 4 || menuSelection != 5 || menuSelection != 6)
            {
                Console.WriteLine("Main Menu\n");
                Console.WriteLine("1 - Add Droid");
                Console.WriteLine("2 - Sort Droid List By Model");
                Console.WriteLine("3 - Sort Droid List By Total Cost");
                Console.WriteLine("4 - Print Current Droid List");
                Console.WriteLine("5 - Reset Droid List: Populates List With Random Droids For Testing");
                Console.WriteLine("6 - Exit\n");
                Console.Write("Enter Number: ");



                try
                {
                    menuSelection = int.Parse(Console.ReadLine());
                    Console.WriteLine();
                    if (menuSelection == 1)
                    {
                        AddDroid();
                    }
                    if (menuSelection == 2)
                    {
                        try
                        {
                            droidCollection.BucketSort();      //This line will call the bucket sort method from the droid collection class, and sort the droid list by Model.
                            Console.WriteLine("Sort Successful, Press 4 To See Sorted Droid List\n");
                        }
                        catch
                        {
                            Console.WriteLine("Sort Unsuccessful\n");
                        }
                    }
                    if (menuSelection == 3)
                    {
                        try
                        {
                            droidCollection.MergeSort();       //This line will call the merge sort method from the droid collection class, and sort the droid list by Total Cost.
                            Console.WriteLine("Sort Successful, Press 4 To See Sorted Droid List\n");
                        }
                        catch
                        {
                            Console.WriteLine("Sort Unsuccessful\n");
                        }
                    }
                    if (menuSelection == 4)
                    {
                        PrintDroidList();
                    }

                    if (menuSelection == 5)
                    {
                        ResetList();
                    }

                    if (menuSelection == 6)
                    {
                        Environment.Exit(0);
                    }
                    if (menuSelection > 6 || menuSelection < 1)
                    {
                        Console.WriteLine("Input Must Be Integer Between 1 - 6\n");
                    }
                }
                catch
                {
                    Console.WriteLine();
                    Console.WriteLine("Input Error\n");
                }
            }
        }