static void Main(string[] args) { //Set a constant for the droid collection const int droidCollectionSize = 20; //Create instance of UserInterface class UserInterface UI = new UserInterface(); //Create an instance of the DroidCollection class DroidCollection droidCollection = new DroidCollection(droidCollectionSize); //Display the menu and get the response. Store the response in the choice integer int choice = UI.DisplayMenuAndGetUserInput(); while (choice != 3) { switch (choice) { case 1: //Begin process to create droid by displaying initial options menu string[] newDroidInformation = UI.GetNewMaterialInformation(); { droidCollection.AddNewItem(newDroidInformation[0], newDroidInformation[1], newDroidInformation[2]); UI.DisplayAddDroidSuccess(); } break; case 2: //Print List of Droids string[] allDroids = droidCollection.GetPrintStringForAllDroids(); if (allDroids.Length > 0) { //Display all of the Droids UI.DisplayAllDroids(allDroids); } else { //Display error message for Droids UI.DisplayAllDroidsError(); } break; } } if (choice == 3) { Environment.Exit(0); } }
static void Main(string[] args) { //*************************************** //Variables //*************************************** string materialTest = "plastic"; string DroidTypeTest = "Protocol"; string colorTest = "red"; int numberLanguagesTest = 1000; int menuChoice; const int DROID_COLLECTION_SIZE = 1000; //Create a single DroidCollection to be used for the entire program DroidCollection droidCollection = new DroidCollection(DROID_COLLECTION_SIZE); //Create a single UserInterface to be used for the entire program UserInterface ui = new UserInterface(); //Create the console to be used ui.StartUserInterface(); //Create the LoadMenu and load the user choice menuChoice = ui.LoadMenu(); // Either user wants to load a droid list or not switch (menuChoice) { case 1: droidCollection.AddNewItem(materialTest, DroidTypeTest, colorTest, numberLanguagesTest); droidCollection.AddNewItem("steele", "Utility", "white", true, true, true); droidCollection.AddNewItem("Plass-Steele", "Janitor", "blue", true, true, false, true, true); droidCollection.AddNewItem("Nevo-Titanium", "Astromech", "orange", true, false, true, true, 10); ui.ListLoadedMessage(); break; case 2: // If droidCollection was not created need to start by adding a droid. ui.AddDroidSequence(droidCollection); break; } //Continue to loop until the user chooses 4 which is to exit. while (menuChoice != 4) { menuChoice = ui.MainMenu(); switch (menuChoice) { case 1: //Print out the droid list ui.PrintDroidList(droidCollection.GetListOfAllDroids()); break; case 2: //Add a new droid to the DroidCollection ui.AddDroidSequence(droidCollection); break; case 3: //Delete a droid from the DroidCollection //Make sure the DroidCollection has Droids in them if (droidCollection.NumberOfDroidsInList > 0) { ui.PrintDroidList(droidCollection.GetListOfAllDroids()); ui.DeleteDroid(droidCollection); } else { ui.NoDroidsInListMessage(); } break; default: //Exit the program ui.ExitMessage(); break; } } }
/// <summary> /// Adds a droid to the Droid Collection by getting user information /// </summary> /// <param name="droidCollection">DroidCollection</param> public void AddDroidSequence(DroidCollection droidCollection) { //*************************************** //Local Variables //*************************************** //All Droids string materialString; string modelString; string colorString; //Protocol Droids int numberLanguagesInt; //Janitor Droids bool trashCompactorBool; bool vacuumBool; //Astromech Droids bool fireExtinquisher; int numberShips; //Get the user data of the type of droid to be added ConsoleKeyInfo inputChar = DroidTypeMenu(); Console.WriteLine(); //Make sure the user inputs the correct data while (inputChar.KeyChar != '1' && inputChar.KeyChar != '2' && inputChar.KeyChar != '3' && inputChar.KeyChar != '4') { ErrorMessage(); inputChar = DroidTypeMenu(); Console.WriteLine(); } // Parse the validated user data int droidTypeInputInt = int.Parse(inputChar.KeyChar.ToString()); //Get the type of the Droid from the modelString modelString = _droidList[droidTypeInputInt - 1]; //Get the type of materail from the user int materialTypeInputInt = DroidMaterialMenu(); //Get the type of material from the materalString based on the user input materialString = _materialList[materialTypeInputInt - 1, 0]; //Get the color from the user colorString = DroidColorMenu(); //Takes the base droid type and get additonal information for each droid type than adds the droid to the DroidCollection switch (droidTypeInputInt) { case 1: //Protocol //Get the number of languges from the user numberLanguagesInt = NumberInput("How many languages do you wish the droid to understand?"); //Add droid to DroidCollection droidCollection.AddNewItem(materialString, modelString, colorString, numberLanguagesInt); break; case 2: //Utility //Call the method to get the input from user for the Utility Droid BaseUtilityDroidInputs(); //Add droid to DroidCollection droidCollection.AddNewItem(materialString, modelString, colorString, toolboxBool, computerConnectionBool, armBool); break; case 3: //Janitor //Call the method to get the input from user for the Utility Droid BaseUtilityDroidInputs(); //Find out if the user wants a trash compactor trashCompactorBool = BoolInput("Do you wish for your droid to have a trash compactor"); //Find out if the user wants a Vacuum vacuumBool = BoolInput("Do you wish for your droid to have a vacuum"); //Add droid to DroidCollection droidCollection.AddNewItem(materialString, modelString, colorString, toolboxBool, computerConnectionBool, armBool, trashCompactorBool, vacuumBool); break; default: //Astromech //Call the method to get the input from user for the Utility Droid BaseUtilityDroidInputs(); //Find out if the user wants a fire extinguiser fireExtinquisher = BoolInput("Do you wish for your droid to have fire extinquisher"); //Find out the number of ships the mech has data on numberShips = NumberInput("How many ships do you wish the droid to have data on?"); //Add droid to DroidCollection droidCollection.AddNewItem(materialString, modelString, colorString, toolboxBool, computerConnectionBool, armBool, fireExtinquisher, numberShips); break; } //Print out the Droid added message DroidAddedMessage(); }