Пример #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 != 3)
            {
                // 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;
                }
                // Re-display the menu, and re-prompt for the choice
                userInterface.DisplayMainMenu();
                choice = userInterface.GetMenuChoice();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            string menuChoice      = null;
            string droidTypeChoice = null;

            string outputString = "";

            // instantiate the user interface
            UserInterface aMenu = new UserInterface();

            // instantiate the collection
            DroidCollection collection = new DroidCollection();

            DisplayMainMenu();

            // Main menu
            void DisplayMainMenu()
            {
                Console.Clear();
                Console.Write(aMenu.MainMenu());
                Console.Write("\n\n\t\t\t\t\t");
                menuChoice = Console.ReadLine();
                HandleMainMenuInput(menuChoice);
            }

            // droid menu
            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);
            }

            // main menu input handler
            void HandleMainMenuInput(string userSelection)
            {
                userSelection = userSelection.ToUpper();
                switch (userSelection)
                {
                case "P":
                    Console.Write(aMenu.PrintListMessage());
                    string[] allDroids = collection.PrintTheDroidsInventory();
                    //aMenu.PrintDroidList(allDroids);
                    aMenu.Pause();

                    // be sure to add a prompt for user interaction with printed list
                    DisplayMainMenu();
                    break;

                case "A":
                    DisplayDroidMenu();
                    break;

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

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

            // 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();
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            // New instance of the User Interface and Droid Collection classes
            UserInterface   ui = new UserInterface();
            DroidCollection dc = new DroidCollection();

            Protocol pro = new Protocol();

            //Get some input from the user
            int choice = ui.GetUserInput();

            // While the choice is not 3, continue.
            while (choice != 3)
            {
                // Check if input is 1
                if (choice == 1)
                {
                    dc.PrintArray();
                }

                // Check if input is 2
                if (choice == 2)
                {
                    ui.PrintDroidOptions();
                    string input = Console.ReadLine();

                    // While the input is not valid re-get the input
                    while (input != "1" &&
                           input != "2" &&
                           input != "3" &&
                           input != "4")
                    {
                        //Print Error message
                        ui.PrintErrorMessage();

                        //Re-print the options
                        ui.PrintDroidOptions();

                        //Get the input from the console again.
                        input = Console.ReadLine();
                    }
                    // Switch statement to add new droids to the list.
                    switch (input)
                    {
                    // Adds a protocol droid
                    case "1":
                        string[] newPDroidInformation = ui.GetNewProtocolDroid();
                        dc.AddNewProtocolDroid(newPDroidInformation[0],
                                               newPDroidInformation[1],
                                               int.Parse(newPDroidInformation[2]));
                        // Possible location for this?
                        //pro.CalculateTotalCost();
                        break;

                    // Adds a utility droid
                    case "2":
                        string[] newUDroidInformation = ui.GetNewUtilityDroid();
                        dc.AddNewUtilityDroid(newUDroidInformation[0],
                                              newUDroidInformation[1],
                                              newUDroidInformation[2] == "True",
                                              newUDroidInformation[3] == "True",
                                              newUDroidInformation[4] == "True");
                        break;

                    // Adds a janitor droid
                    case "3":
                        string[] newJDroidInformation = ui.GetNewJanitorDroid();
                        dc.AddNewJanitorDroid(newJDroidInformation[0],
                                              newJDroidInformation[1],
                                              newJDroidInformation[2] == "True",
                                              newJDroidInformation[3] == "True",
                                              newJDroidInformation[4] == "True",
                                              newJDroidInformation[5] == "True",
                                              newJDroidInformation[6] == "True");
                        break;

                    // Adds an astromech droid
                    case "4":
                        string[] newADroidInformation = ui.GetNewAstromechDroid();
                        dc.AddNewAstromechDroid(newADroidInformation[0],
                                                newADroidInformation[1],
                                                newADroidInformation[2] == "True",
                                                newADroidInformation[3] == "True",
                                                newADroidInformation[4] == "True",
                                                newADroidInformation[5] == "True",
                                                int.Parse(newADroidInformation[6]));
                        break;
                    }
                }
                // Prompt the user for input
                choice = ui.GetUserInput();
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            // Boolean to see if it should print the heading for new Droid
            bool validation = false;

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

            //Let's make an array to hold a bunch of instances of the Droid class
            Droid[] droids = new Droid[100];

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

            // array to hold pre-loaded droids
            droids[0] = new ProtocolDroid("C3PO", "Protocol", "Gold", "Gold", 5); //droids[0] = new ProtocolDroid("C3PO", "Protocol", "Gold", "Gold", 35.00m, 45.00m);
            droids[1] = new UtilityDroid("BD1", "Utility", "Amethyst", "Red", true, true, true);
            droids[2] = new AstromechDroid("R2D2", "Astromech", "Iron", "Blue", true, true, true, true, 1);
            droids[3] = new JanitorDroid("A1Z4", "Janitor", "Iron", "Black", true, true, true, true, true);


            // 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 != 3)
            {
                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();
                        // Boolean for option 2
                        validation = true;
                    }
                    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
                        validation = true;
                    }
                    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();
                        // Boolean for option 2
                        validation = true;
                    }
                    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();
                        // Boolean for option 2
                        validation = true;
                    }
                    break;

                // Print Droid List
                case 2:
                    // Tests to see if user already added a Droid
                    if (validation == true)
                    {
                        // Output New Droid heading
                        ui.NewDroidsOutputHeading();

                        // Output Heading
                        ui.DisplayDroidHeader();

                        // Output New Droids
                        ui.Output(droidCollection.ToString());
                    }
                    else
                    {
                        // Display error message
                        ui.DisplayErrorNoNewDroids();
                    }

                    // Output Pre-Loaded Droid heading
                    ui.PreLoadedDroidsOutputHeading();

                    // Output Heading again for pre-loaded Droids
                    ui.DisplayDroidHeader();

                    // Declare a return string
                    string outputString = "";

                    // Loop through all of the droids
                    foreach (Droid droid in droids)
                    {
                        // If the current beverage is not null, concat it to the return string
                        if (droid != null)
                        {
                            //Concat to the outputString
                            outputString += droid.ToString() +
                                            Environment.NewLine;
                        }
                    }
                    // Output preloaded Droids
                    ui.Output(outputString);
                    outputString = "";
                    break;
                }
                // Get the new choice of what to do from the user
                choice = ui.DisplayMenuAndGetResponse();
            }
        }