Пример #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();

            // While the choice is not equal to 3, 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;

                // Choose to sort based on droid type
                case 3:
                    droidCollection.CategorySort();
                    break;

                // Choose to sort based on total cost
                case 4:
                    droidCollection.TotalCostSort();
                    break;
                }
                // Re-display the menu, and re-prompt for the choice
                userInterface.DisplayMainMenu();
                choice = userInterface.GetMenuChoice();
            }
        }
Пример #2
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 few droids to put into the list so that they do not NEED to be made through the UI
            droidCollection.Add(Droid.Materials.Carbonite, Droid.Colors.White, 12);
            droidCollection.Add(Droid.Materials.Vanadium, Droid.Colors.Red, true, true, true);
            droidCollection.Add(Droid.Materials.Quadranium, Droid.Colors.Blue, true, true, true, true, true);
            droidCollection.Add(Droid.Materials.Tears_Of_A_Jedi, Droid.Colors.Green, true, true, false, true, 80);
            droidCollection.Add(Droid.Materials.Tears_Of_A_Jedi, Droid.Colors.Blue, 22);
            droidCollection.Add(Droid.Materials.Quadranium, Droid.Colors.Red, false, false, false, false, true);
            droidCollection.Add(Droid.Materials.Vanadium, Droid.Colors.White, true, true, false);
            droidCollection.Add(Droid.Materials.Carbonite, Droid.Colors.Green, false, true, false, true, 150);
            droidCollection.Add(Droid.Materials.Carbonite, Droid.Colors.Green, false, true, true, true, true);
            droidCollection.Add(Droid.Materials.Vanadium, Droid.Colors.White, true, false, true);
            droidCollection.Add(Droid.Materials.Quadranium, Droid.Colors.Red, true, false, false, true, 100);
            droidCollection.Add(Droid.Materials.Tears_Of_A_Jedi, Droid.Colors.Blue, false, true, false, true, true);

            // 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();

            // While the choice is not equal to 3, 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;

                // Print in categorical order
                case 3:
                    droidCollection.SortIntoCategories();
                    userInterface.DisplaySortCategoriesSuccessMessage();
                    break;

                // Print in categorical order
                case 4:
                    droidCollection.SortByTotalCost();
                    userInterface.DisplaySortTotalCostSuccessMessage();
                    break;
                }
                // Re-display the menu, and re-prompt for the choice
                userInterface.DisplayMainMenu();
                choice = userInterface.GetMenuChoice();
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            UserInterface   aMenu      = new UserInterface();
            DroidCollection collection = new DroidCollection();

            DisplayMainMenu();

            void DisplayMainMenu()
            {
                Console.Clear();
                Console.Write(aMenu.MainMenu());
                Console.Write("\n\n\t\t\t");
                var menuChoice = Console.ReadLine();

                HandleMainMenuInput(menuChoice);
            }

            void DisplayDroidMenu()
            {
                Console.Clear();
                Console.ResetColor();
                Console.Write(aMenu.DroidSelection());
                Console.Write("\n\n\t\t\t\t\t");
                string droidType = Console.ReadLine().ToUpper();

                HandleDroidMenuInput(droidType);
            }

            void HandleMainMenuInput(string userSelection)
            {
                userSelection = userSelection.ToUpper();
                switch (userSelection)
                {
                case "A":
                    DisplayDroidMenu();
                    break;

                case "T":
                    AddTestData();
                    Console.WriteLine(aMenu.TestDataAdded());
                    aMenu.Pause();
                    DisplayMainMenu();
                    break;

                case "P":
                    if (IsEmpty())
                    {
                        Console.WriteLine(aMenu.NothingToPrint());
                        aMenu.Pause();
                    }
                    else
                    {
                        Console.Write(aMenu.PrintListMessage());
                        string[] allDroids = collection.PrintTheDroidsInventory();
                        aMenu.WaitForUser();
                    }
                    DisplayMainMenu();
                    break;

                case "C":
                    if (IsEmpty())
                    {
                        Console.WriteLine(aMenu.NothingToSort());
                    }
                    else
                    {
                        collection.CategorizeByModel();
                        Console.WriteLine(aMenu.DroidsSortedByCategory());
                    }
                    aMenu.Pause();
                    DisplayMainMenu();
                    break;

                case "M":
                    if (IsEmpty())
                    {
                        Console.WriteLine(aMenu.NothingToSort());
                    }
                    else
                    {
                        collection.MergeSortByTotalCost();
                        Console.WriteLine(aMenu.DroidsSortedByTotalCost());
                    }
                    aMenu.Pause();
                    DisplayMainMenu();
                    break;

                case "Q":
                    Console.WriteLine(aMenu.QuitProgramMessage());
                    aMenu.Pause();
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine(aMenu.InvalidOptionMessage());
                    aMenu.Pause();
                    DisplayMainMenu();
                    break;
                }
            }

            void AddTestData()
            {
                // protocol
                collection.Add("Polyskin", "Red", 6);
                collection.Add("Metaskin", "Black", 23);
                collection.Add("Ceraskin", "White", 13);

                //astromech
                collection.Add("Polyskin", "White", false, false, true, true, 12);
                collection.Add("Metaskin", "Black", false, false, false, true, 36);
                collection.Add("Metaskin", "Red", false, true, false, true, 24);

                //janitor
                collection.Add("Ceraskin", "Red", false, true, false, true, false);
                collection.Add("Metaskin", "White", false, false, true, false, false);
                collection.Add("Polyskin", "Black", true, false, true, true, true);

                //utility
                collection.Add("Metaskin", "Red", false, true, false);
                collection.Add("Polyskin", "White", true, true, false);
                collection.Add("Ceraskin", "Black", true, false, true);
            }

            // droid menu input handler
            void HandleDroidMenuInput(string droidType)
            {
                switch (droidType)
                {
                case "P":
                    string[] protocol = aMenu.BuildProtocolDroid();
                    if (aMenu.ValidateDroidEntries(protocol))
                    {
                        collection.Add(protocol[0], protocol[1], int.Parse(protocol[2]));
                        Console.WriteLine(aMenu.DroidAdded());
                    }
                    else
                    {
                        InvalidInformation();
                    }
                    break;

                case "U":
                    string[] utility = aMenu.BuildAUtilityDroid();
                    if (aMenu.ValidateDroidEntries(utility))
                    {
                        collection.Add(utility[0], utility[1], bool.Parse(utility[2]), bool.Parse(utility[3]), bool.Parse(utility[4]));
                        Console.WriteLine(aMenu.DroidAdded());
                    }
                    else
                    {
                        InvalidInformation();
                    }
                    break;

                case "J":
                    string[] janitor = aMenu.BuildAJanitorDroid();
                    if (aMenu.ValidateDroidEntries(janitor))
                    {
                        collection.Add(janitor[0], janitor[1], bool.Parse(janitor[2]), bool.Parse(janitor[3]), bool.Parse(janitor[4]), bool.Parse(janitor[5]), bool.Parse(janitor[6]));
                        Console.WriteLine(aMenu.DroidAdded());
                    }
                    else
                    {
                        InvalidInformation();
                    }
                    break;

                case "A":
                    string[] astromech = aMenu.BuildAnAstromechDroid();
                    if (aMenu.ValidateDroidEntries(astromech))
                    {
                        collection.Add(astromech[0], astromech[1], bool.Parse(astromech[2]), bool.Parse(astromech[3]), bool.Parse(astromech[4]), bool.Parse(astromech[5]), int.Parse(astromech[6]));
                        Console.WriteLine(aMenu.DroidAdded());
                    }
                    else
                    {
                        InvalidInformation();
                    }

                    break;

                case "M":
                    DisplayMainMenu();
                    break;

                default:
                    Console.WriteLine(aMenu.InvalidOptionMessage());
                    aMenu.Pause();
                    break;
                }
                aMenu.Pause();
                DisplayDroidMenu();
            }

            // The Badlands
            void InvalidInformation()
            {
                Console.Write(aMenu.InvalidInformation());
                aMenu.Pause();
                Console.ResetColor();
            }

            bool IsEmpty()
            {
                return(collection.IsEmpty(collection.GetDroidArray()));
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            // Set a constant for the size of the droidCollection
            const int droidCollectionSize = 100;

            // Make a new instance of the User Interface class
            UserInterface ui = new UserInterface();

            // Create an instance of the DroidCollection class
            DroidCollection droidCollection = new DroidCollection(droidCollectionSize);

            // array to hold pre-loaded droids
            droidCollection.AddNewProtocolDroid("C3PO", "Protocol", "Gold", "Gold", 5);
            droidCollection.AddNewUtilityDroid("BD1", "Utility", "Amethyst", "Red", true, true, true);
            droidCollection.AddNewAstromechDroid("R2D2", "Astromech", "Iron", "Blue", true, true, true, true, 1);
            droidCollection.AddNewJanitorDroid("A1Z4", "Janitor", "Iron", "Black", true, true, true, true, true);
            droidCollection.AddNewProtocolDroid("P0L0", "Protocol", "Amethyst", "Purple", 3);

            // Display the Welcome Message to the user
            ui.DisplayWelcomeGreeting();

            // Display the Menu and get the response. Store the response in the choice integer
            // This is the 'primer' run of displaying and getting.
            int choice = ui.DisplayMenuAndGetResponse();

            // While the choice selected is not, continue to do work
            while (choice != 5)
            {
                switch (choice)
                {
                // Add A New Droid To The List
                case 1:
                    // User Interface gets the droid type
                    string type = ui.GetDroidTypeInformation();

                    // Tests if type is protocol, utility, janitor, or astromech
                    if (type == "Protocol" || type == "protocol")
                    {
                        // Calls the UI for new Droid info and sets it to an array string
                        string[] newDroidInformation = ui.GetNewProtocolDroidInformation();
                        // Adds the new droid to the droidCollection class
                        droidCollection.AddNewProtocolDroid(newDroidInformation[0],
                                                            newDroidInformation[1],
                                                            newDroidInformation[2],
                                                            newDroidInformation[3],
                                                            int.Parse(newDroidInformation[4]));

                        // Display add droid succession
                        ui.DisplayAddDroidItemSuccess();
                    }
                    if (type == "Utility" || type == "utility")
                    {
                        // Calls the UI for new Droid info and sets it to an array string
                        string[] newDroidInformation = ui.GetNewUtilityDroidInformation();

                        // Adds the new droid to the droidCollection class
                        droidCollection.AddNewUtilityDroid(newDroidInformation[0],
                                                           newDroidInformation[1],
                                                           newDroidInformation[2],
                                                           newDroidInformation[3],
                                                           bool.Parse(newDroidInformation[4]),
                                                           bool.Parse(newDroidInformation[5]),
                                                           bool.Parse(newDroidInformation[6]));
                        // Display add droid succession
                        ui.DisplayAddDroidItemSuccess();
                        // Boolean for option 2
                    }
                    if (type == "Janitor" || type == "janitor")
                    {
                        // Calls the UI for new Droid info and sets it to an array string
                        string[] newDroidInformation = ui.GetNewJanitorDroidInformation();

                        // Adds the new droid to the droidCollection class
                        droidCollection.AddNewJanitorDroid(newDroidInformation[0],
                                                           newDroidInformation[1],
                                                           newDroidInformation[2],
                                                           newDroidInformation[3],
                                                           bool.Parse(newDroidInformation[4]),
                                                           bool.Parse(newDroidInformation[5]),
                                                           bool.Parse(newDroidInformation[6]),
                                                           bool.Parse(newDroidInformation[7]),
                                                           bool.Parse(newDroidInformation[8]));
                        // Display add droid succession
                        ui.DisplayAddDroidItemSuccess();
                    }
                    if (type == "Astromech" || type == "astromech")
                    {
                        // Calls the UI for new Droid info and sets it to an array string
                        string[] newDroidInformation = ui.GetNewAstromechDroidInformation();

                        // Adds the new droid to the droidCollection class
                        droidCollection.AddNewAstromechDroid(newDroidInformation[0],
                                                             newDroidInformation[1],
                                                             newDroidInformation[2],
                                                             newDroidInformation[3],
                                                             bool.Parse(newDroidInformation[4]),
                                                             bool.Parse(newDroidInformation[5]),
                                                             bool.Parse(newDroidInformation[6]),
                                                             bool.Parse(newDroidInformation[7]),
                                                             int.Parse(newDroidInformation[8]));
                        // Display add droid succession
                        ui.DisplayAddDroidItemSuccess();
                    }
                    break;

                // Print Droid List
                case 2:
                    // Output New Droid heading
                    ui.NewDroidsOutputHeading();

                    // Output Heading
                    ui.DisplayDroidHeader();

                    // Output New Droids
                    ui.Output(droidCollection.ToString());
                    break;

                // Categorize by model
                case 3:
                    // Output Categorizing Header
                    ui.DisplayCategorizingHeader();

                    // Output Heading
                    ui.DisplayDroidHeader();

                    droidCollection.CategorizeByModel();
                    break;

                // Sort by Total Cost
                case 4:
                    //MergeSort merge = new MergeSort();

                    // Output Sorting Header
                    ui.DisplaySortingHeader();

                    Droid.

                    // Merge call
                    droidCollection.SendToMerge();

                    // Output Heading
                    ui.DisplayDroidHeader();

                    // Output New Droids
                    ui.Output(droidCollection.ToString());

                    break;
                }
                // Get the new choice of what to do from the user
                choice = ui.DisplayMenuAndGetResponse();
            }
        }