private UI userInterface = new UI(); //instanciates user interface #endregion Fields #region Methods //method used for adding an Astromech droid public void AddAstromechDroid() { model = "Astromech"; //model is named Astromech material = userInterface.GetDroidMaterial(); //user interface asks user which material to pick from color = userInterface.GetDroidColor(); //user interface asks user which color to pick from toolbox = userInterface.GetToolbox(); //user interface asks user if they want a toolbox for their droid computerConnection = userInterface.GetCompConnection(); //user interface asks user if they want a computer connection for their droid arm = userInterface.GetArm(); //user interface asks user if they want an extra arm for their droid bool fireExtinguisher = userInterface.GetFireExtinguisher(); //user interface asks user if they want a fire extinguisher for their droid int numberShips = userInterface.GetNumberShips(); //user interface asks user how many ships they want droids[positionInArray] = new AstromechDroid(material, model, color, toolbox, computerConnection, arm, fireExtinguisher, numberShips); //final droid is added to the array totalCost = droids[positionInArray].CalculateTotalCost(); //total cost is determined based on droid type Console.WriteLine(Environment.NewLine + "Final Specs:" + //droid specs are printed to the console for the user to see Environment.NewLine + droids[positionInArray] + " " + totalCost.ToString("C") + Environment.NewLine); positionInArray++; //array index is changed so the recently added droid will not be overwritten }
public void AddAstromechDroid() //method used for adding an Astromech droid { model = "Astromech"; //model is named Astromech material = userInterface.GetDroidMaterial(); //user interface asks user which material to pick from color = userInterface.GetDroidColor(); //user interface asks user which color to pick from toolbox = userInterface.GetToolbox(); //user interface asks user if they want a toolbox for their droid computerConnection = userInterface.GetCompConnection(); //user interface asks user if they want a computer connection for their droid arm = userInterface.GetArm(); //user interface asks user if they want an extra arm for their droid bool fireExtinguisher = userInterface.GetFireExtinguisher(); //user interface asks user if they want a fire extinguisher for their droid int numberShips = userInterface.GetNumberShips(); //user interface asks user how many ships they want droids[positionInArray] = new AstromechDroid(material, model, color, toolbox, computerConnection, arm, fireExtinguisher, numberShips); //final droid is added to the array totalCost = droids[positionInArray].CalculateTotalCost(); //total cost is determined based on droid type Console.WriteLine(Environment.NewLine + "Final Specs:" + //droid specs are printed to the console for the user to see Environment.NewLine + droids[positionInArray] + " " + totalCost.ToString("C") + Environment.NewLine); positionInArray++; //array index is changed so the recently added droid will not be overwritten }
/// <summary> /// adds a droid to the inventory /// </summary> private void addDroid() { Console.WriteLine("please choose a droid type:"); for (int i = 0; i < listOfPrices.Length; i++) { Console.WriteLine((i + 1) + ": " + listOfPrices[i].model); } String selection = Console.ReadLine(); int selectionInt; Console.Clear(); if (int.TryParse(selection, out selectionInt) && selectionInt <= listOfPrices.Length) { Console.WriteLine(listOfPrices[selectionInt - 1].model + Environment.NewLine); switch (listOfPrices[selectionInt - 1].model) { case "astromech": Inventory.Add(AstromechDroid.CreateDroid()); break; case "protocol": Inventory.Add(ProtocolDroid.CreateDroid()); break; case "janitor": Inventory.Add(JanitorDroid.CreateDroid()); break; case "utility": Inventory.Add(UtilityDroid.CreateDroid()); break; default: Console.WriteLine("Error, unknown droid type"); break; } Console.Clear(); } else { Console.WriteLine("invalid Input, {0}", selection); } }
int _freeSpot = 0; // >Marks the location to add a new droid. #endregion Fields #region Methods // >Add a droid to the list. public void AddADroid() { int modelChoice = 0; string newDroidModel = string.Empty; string newDroidMaterial = string.Empty; string newDroidColor = string.Empty; // >Set the model. SelectModel(ref newDroidModel, ref modelChoice); // >Set the material. SelectMaterial(ref newDroidMaterial); // >Set the color. SelectColor(ref newDroidColor); // >These choices depend on the model chosen. switch (modelChoice) { // >MC stands for Model Catagory. case PROTOCOL_MC: int newDroidNumOfLanguages = 0;// >The number of languages that the droid knows. // >Select the number of languages. SelectNumberOfLanquages(ref newDroidNumOfLanguages); // >Create a new droid in the array's free spot. droidsArray[_freeSpot] = new ProtocolDroid(newDroidModel, newDroidMaterial, newDroidColor, newDroidNumOfLanguages); break; case UTILITY_MC: case JANITOR_MC: case ASTROMECH_MC: bool newDroidToolBox = false;// >If the droid has a toolbox. bool newDroidComputerConnection = false;// >If the droid has a computer connection. bool newDroidArm = false;// >If the droid has and newDroidArm. // >set if it has a tool box. SelectToolBoxBool(ref newDroidToolBox); // >Set if it has a computer connection. SelectComputerConnectionBool(ref newDroidComputerConnection); // >Set if it has an arm. SelectArmBool(ref newDroidArm); if (modelChoice == UTILITY_MC) { // >Create a new droid in the array's free spot. droidsArray[_freeSpot] = new UtilityDroid(newDroidModel, newDroidMaterial, newDroidColor, newDroidToolBox, newDroidComputerConnection, newDroidArm); } else { switch (modelChoice) { case JANITOR_MC: bool newDroidTrashCompactor = false;// >If the droid has a trash compactor. bool newDroidVacuum = false;// >If the droid has a vacuum. // >Set if it has a trash compactor. SelectTrashCompactorBool(ref newDroidTrashCompactor); // >Set if it has a vacuum. SelectVacuumBool(ref newDroidVacuum); // >Create a new droid in the array's free spot. droidsArray[_freeSpot] = new JanitorDroid(newDroidModel, newDroidMaterial, newDroidColor, newDroidToolBox, newDroidComputerConnection, newDroidArm, newDroidTrashCompactor, newDroidVacuum); break; case ASTROMECH_MC: bool newDroidFireExtinquisher = false;// >If the droid has a FireExtinquisher. int newDroidNumberOfShips = 0;// >The number of ships the droid has worked on. // >Set if it has a FireExtinquisher. SelectFireExtinquisherBool(ref newDroidFireExtinquisher); // >Set the number of ships worked on. SelectNumberOfShips(ref newDroidNumberOfShips); // >Create a new droid in the array's free spot. droidsArray[_freeSpot] = new AstromechDroid(newDroidModel, newDroidMaterial, newDroidColor, newDroidToolBox, newDroidComputerConnection, newDroidArm, newDroidFireExtinquisher, newDroidNumberOfShips); break; } } break; } // >Inform the user that the addition was successful. UserInterface.WriteToScreen(""); UserInterface.WriteToScreen("-- The droid has been added to the list --"); UserInterface.WriteToScreen(""); // >Change the free spot. _freeSpot++; }
public void add(string model, string material, string color, bool toolbox, bool computer, bool arm, bool fire, int ships) { droids[currentIndex++] = new AstromechDroid(model, material, color, toolbox, computer, arm, fire, ships); }
/// <summary> /// Add an Astromech Droid /// </summary> /// <param name="material">The material string name</param> /// <param name="model">The model string text</param> /// <param name="color">The color string name</param> /// <param name="toolbox">Does this Droid have a toolbox?</param> /// <param name="computerConnection">Does this Droid have a computer connection?</param> /// <param name="arm">Does this Droid have an arm?</param> /// <param name="fireExtinguisher">Does this Droid have a fire extinguisher?</param> /// <param name="numberShips">How many ships will this droid interface with?</param> public void AddDroid(string material, string model, string color, bool toolbox, bool computerConnection, bool arm, bool fireExtinguisher, int numberShips) { AstromechDroid droid = new AstromechDroid(material, model, color, toolbox, computerConnection, arm, fireExtinguisher, numberShips); this.AddDroid(droid); }
Droid[] droidsArray = new Droid[100]; // >Holds all of the droids. // >Add a droid to the list. public void AddADroid() { int modelChoice = 0; string newDroidModel = string.Empty; string newDroidMaterial = string.Empty; string newDroidColor = string.Empty; // >Set the model. SelectModel(ref newDroidModel, ref modelChoice); // >Set the material. SelectMaterial(ref newDroidMaterial); // >Set the color. SelectColor(ref newDroidColor); // >These choices depend on the model chosen. switch (modelChoice) { // >MC stands for Model Catagory. case PROTOCOL_MC: int newDroidNumOfLanguages = 0; // >The number of languages that the droid knows. // >Select the number of languages. SelectNumberOfLanquages(ref newDroidNumOfLanguages); // >Create a new droid in the array's free spot. droidsArray[_freeSpot] = new ProtocolDroid(newDroidModel, newDroidMaterial, newDroidColor, newDroidNumOfLanguages); break; case UTILITY_MC: case JANITOR_MC: case ASTROMECH_MC: bool newDroidToolBox = false; // >If the droid has a toolbox. bool newDroidComputerConnection = false; // >If the droid has a computer connection. bool newDroidArm = false; // >If the droid has and newDroidArm. // >set if it has a tool box. SelectToolBoxBool(ref newDroidToolBox); // >Set if it has a computer connection. SelectComputerConnectionBool(ref newDroidComputerConnection); // >Set if it has an arm. SelectArmBool(ref newDroidArm); if (modelChoice == UTILITY_MC) { // >Create a new droid in the array's free spot. droidsArray[_freeSpot] = new UtilityDroid(newDroidModel, newDroidMaterial, newDroidColor, newDroidToolBox, newDroidComputerConnection, newDroidArm); } else { switch (modelChoice) { case JANITOR_MC: bool newDroidTrashCompactor = false; // >If the droid has a trash compactor. bool newDroidVacuum = false; // >If the droid has a vacuum. // >Set if it has a trash compactor. SelectTrashCompactorBool(ref newDroidTrashCompactor); // >Set if it has a vacuum. SelectVacuumBool(ref newDroidVacuum); // >Create a new droid in the array's free spot. droidsArray[_freeSpot] = new JanitorDroid(newDroidModel, newDroidMaterial, newDroidColor, newDroidToolBox, newDroidComputerConnection, newDroidArm, newDroidTrashCompactor, newDroidVacuum); break; case ASTROMECH_MC: bool newDroidFireExtinquisher = false; // >If the droid has a FireExtinquisher. int newDroidNumberOfShips = 0; // >The number of ships the droid has worked on. // >Set if it has a FireExtinquisher. SelectFireExtinquisherBool(ref newDroidFireExtinquisher); // >Set the number of ships worked on. SelectNumberOfShips(ref newDroidNumberOfShips); // >Create a new droid in the array's free spot. droidsArray[_freeSpot] = new AstromechDroid(newDroidModel, newDroidMaterial, newDroidColor, newDroidToolBox, newDroidComputerConnection, newDroidArm, newDroidFireExtinquisher, newDroidNumberOfShips); break; } } break; } // >Inform the user that the addition was successful. UserInterface.WriteToScreen(""); UserInterface.WriteToScreen("-- The droid has been added to the list --"); UserInterface.WriteToScreen(""); // >Change the free spot. _freeSpot++; }