//displays the main menu and asks for input public void DisplayMainMenu(List <Droid> droid, DroidCollection droidCollection) { bool quitMain = false; do { Console.WriteLine("Welcome to Droid manager"); Console.WriteLine("Enter the number of the desired choice"); Console.WriteLine("1.Add a Droid"); Console.WriteLine("2.Print the list of Droids"); Console.WriteLine("3.Exit"); Console.Write("Select an option: "); string optionSelection = Console.ReadLine(); if (optionSelection == "1") { addDroidUI(droid, droidCollection); } else if (optionSelection == "2") { droidCollection.printDroidList(droid); } else if (optionSelection == "3") { Console.WriteLine("Goodbye"); Environment.Exit(0); } } while (quitMain != true); }
/// <summary> /// Finds out which Droid the user wants deleted and deletes it /// </summary> /// <param name="droidCollection">DroidCollection</param> public void DeleteDroid(DroidCollection droidCollection) { //Gets the number of the droid to be deleted from the user int droidNumber = GetDroidNumber(droidCollection); //Output the message to confirm the droid to be deleted. Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Droid to delete:"); Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); //Calls the method to print out a single droid from the DroidCollection Console.WriteLine(droidCollection.GetASingleDroid(droidNumber)); Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); //Gets the user input to confirm to delete the droid bool deleteDroid = BoolInput("Are you sure you want to delete the prevous droid?"); if (deleteDroid) {//Delete the droid now that it has been confirmed and tell the user it has been deleted and reprint the list Console.ForegroundColor = ConsoleColor.DarkGreen; droidCollection.DeleteItem(droidNumber); Console.WriteLine("Droid Delted!"); } Console.ForegroundColor = ConsoleColor.White; }
//displays the main menu and asks for input public void DisplayMainMenu(List<Droid> droid, DroidCollection droidCollection) { bool quitMain = false; do { Console.WriteLine("Welcome to Droid manager"); Console.WriteLine("Enter the number of the desired choice"); Console.WriteLine("1.Add a Droid"); Console.WriteLine("2.Print the list of Droids"); Console.WriteLine("3.Exit"); Console.Write("Select an option: "); string optionSelection = Console.ReadLine(); if (optionSelection == "1") { addDroidUI(droid, droidCollection); } else if (optionSelection == "2") { droidCollection.printDroidList(droid); } else if (optionSelection == "3") { Console.WriteLine("Goodbye"); Environment.Exit(0); } } while (quitMain != true); }
static void Main(string[] args) { UserInterface userInterface = new UserInterface(); DroidCollection droidCollection = new DroidCollection(); bool exitBool = false; while (exitBool == false) { int choice = userInterface.MainMenu(); switch (choice) { case 1: Droid inputDroid = userInterface.InputDroid(); droidCollection.AddDroid(inputDroid); break; case 2: string output = droidCollection.ToString(); userInterface.PrintAllOutput(output); break; case 3: exitBool = true; break; default: userInterface.PrintError(); break; } } }
static void Main(string[] args) { UI userInterface = new UI(); //instanciates the user interface DroidCollection droidsCollection = new DroidCollection(); //instanciates the droid collection int userResponse = userInterface.MenuPrompt(); //user is prompted the menu of tasks that the program can perform while (userResponse != 3) //while the user has not selected the option to close the program { switch (userResponse.ToString()) //case structure that uses the user's choice as a reference { case "1": //user has chosen to print the array droidsCollection.ReadArray(); //the method to print the array is called userResponse = userInterface.MenuPrompt(); //user is prompted the menu of tasks that the program can perform break; case "2": //user has chosen to add a droid to the array int modelResponse = userInterface.GetDroidModel(); //method to choose the droid model is called and the user's choice of model is stored as an integer switch (modelResponse.ToString()) //the integer from the above line is used as reference for the case structure { //this case structure runs certain code for each model case "1": //protocol droid case droidsCollection.AddProtocolDroid(); //method to add a new protocol droid userResponse = userInterface.MenuPrompt(); //user is prompted the menu of tasks that the program can perform break; case "2": //utility droid case droidsCollection.AddUtilityDroid(); //method to add new utility droid userResponse = userInterface.MenuPrompt(); //user is prompted the menu of tasks that the program can perform break; case "3": //janitor droid case droidsCollection.AddJanitorDroid(); //method to add new janitor droid userResponse = userInterface.MenuPrompt(); //user is prompted the menu of tasks that the program can perform break; case "4": //astromech droid case droidsCollection.AddAstromechDroid(); //method to add new astromech droid userResponse = userInterface.MenuPrompt(); //user is prompted the menu of tasks that the program can perform break; } break; case "3": //user has chosen to exit the program userInterface.Close(); //method to close the program is called break; default: //user has chosen an invalid option userInterface.InvalidMenuResponse(); //user is told of their invalid response userResponse = userInterface.MenuPrompt(); //user is prompted the menu of tasks that the program can perform break; } } }
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); } }
/// <summary> /// Gets the number of the droid to delete from the user and validates the data /// </summary> /// <param name="droidCollection"></param> /// <returns>int</returns> private int GetDroidNumber(DroidCollection droidCollection) { //Get the number from the user int numberOfDroid = NumberInput("Which numbered droid do you wish to delete?"); //Continue to get the user input until they enter a valid number while ((numberOfDroid < 1) || (numberOfDroid > droidCollection.NumberOfDroidsInList)) { ErrorMessage(); numberOfDroid = NumberInput("Which numbered droid do you wish to delete?"); } //Subtracting one to make it equal to the index return(numberOfDroid - 1); }
static void Main(string[] args) { //instance of droid list object created List<Droid> droid = new List<Droid>(); //instance of user interface UserInterface ui = new UserInterface(); //instance of droid collection DroidCollection droidCollection = new DroidCollection(); //display Main Menu of program ui.DisplayMainMenu(droid, droidCollection); }
static void Main(string[] args) { //instance of droid list object created List <Droid> droid = new List <Droid>(); //instance of user interface UserInterface ui = new UserInterface(); //instance of droid collection DroidCollection droidCollection = new DroidCollection(); //display Main Menu of program ui.DisplayMainMenu(droid, droidCollection); }
static void Main(string[] args) { int option; DroidCollection x = new DroidCollection(); Console.WriteLine("1 would you like to add Drone\n2 print list\n3 calculate total cost"); option = Convert.ToInt32(Console.ReadLine()); while (option == 1) { x.addDroid(); Console.WriteLine("would you like to add another drone?\n1 yes \n2 print list\n3 calculate total\n4 exit"); option = Convert.ToInt32(Console.ReadLine()); } if (option == 2) { x.printList(); } if (option == 3) { x.totalCost(); } }
/// <summary> /// ***********Problems*********** /// Dosen't save to file or print from file correctly /// Not sure if im useing calculate methods from othe classes right /// No UI, Will work before next assgnment /// Not a lot or very detail comment(have to get used to commenting while i code) /// /// </summary> /// <param name="args"></param> static void Main(string[] args) { //Variables string materialSelected = string.Empty; string modelSelected; string colorSelected; bool toolboxSelected; bool computerConnectionSelected; bool armSelected; bool trashCompatSelected; bool vacuumSelected; bool fireExtingSelected; int numOfChips; int numberOfLanguage; string userInput = string.Empty; DroidCollection newDroid = new DroidCollection(); // Console.Write("It Still Runs!!!!!!!!!!!"); while (userInput != "e") { Console.WriteLine("Type n to add a new droid"); Console.WriteLine("Type p to print droid"); Console.WriteLine("Type e to exit"); Console.Write("Select an opetion: "); userInput = Console.ReadLine(); Console.WriteLine("----------------"); if (userInput == "n") { // All droid Units go throuh this procees Console.WriteLine("--------------------"); Console.Write("Material: "); materialSelected = Console.ReadLine(); Console.Write("Model: "); modelSelected = Console.ReadLine(); Console.Write("Color: "); colorSelected = Console.ReadLine(); Console.Write("Droid Model: "); Console.WriteLine("Protocol, Utility, Janitor, Astromech"); Console.WriteLine("selcet a Droid"); userInput = Console.ReadLine(); //if protocol is selceted if (userInput.Equals("protocol", StringComparison.OrdinalIgnoreCase )) { Console.Write("Number of Language: "); numberOfLanguage = Int32.Parse(Console.ReadLine()); newDroid.addProtocolDroid(materialSelected, modelSelected, colorSelected, numberOfLanguage);// adds user input newDroid.saveDroidList();// saves user input Console.WriteLine("------------------"); } // if utility is selected else if (userInput.Equals("utility", StringComparison.OrdinalIgnoreCase )) { Console.Write("Tool box yes or no "); toolboxSelected = ToBool(Console.ReadLine()); Console.Write("Computer Connection yes or no "); computerConnectionSelected = ToBool(Console.ReadLine()); Console.Write("Arm yes or no "); armSelected = ToBool(Console.ReadLine()); newDroid.addUtilityDroid(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected);// adds user input newDroid.saveDroidList();// saves user input } // if janitor is selected else if(userInput.Equals("janitor", StringComparison.OrdinalIgnoreCase )) { Console.Write("Tool box yes or no "); toolboxSelected = ToBool(Console.ReadLine()); Console.Write("Computer Connection yes or no "); computerConnectionSelected = ToBool(Console.ReadLine()); Console.Write("Arm yes or no "); armSelected = ToBool(Console.ReadLine()); Console.Write("Trash Compactoer yes or no "); trashCompatSelected = ToBool(Console.ReadLine()); Console.Write("Vacuum yes or no "); vacuumSelected = ToBool(Console.ReadLine()); newDroid.addJanitorDroid(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected, trashCompatSelected, vacuumSelected);// adds user input newDroid.saveDroidList();// saves user input Janitor janitorCost = new Janitor(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected, trashCompatSelected, vacuumSelected);//creates new Janitor object so we can you the methods eith n that class janitorCost.CalculateBaseCost();// Calculate methods from astromech janitorCost.CalculateTotalCost(); } //If astromec is selected else if (userInput.Equals("astromech" , StringComparison.OrdinalIgnoreCase )) { Console.Write("Tool box yes or no "); toolboxSelected = ToBool(Console.ReadLine()); Console.Write("Computer Connection yes or no "); computerConnectionSelected = ToBool(Console.ReadLine()); Console.Write("Arm yes or no "); armSelected = ToBool(Console.ReadLine()); Console.Write("FireExtingquisher yes or no "); fireExtingSelected = ToBool(Console.ReadLine()); Console.Write("Number of Chips "); numOfChips = Int32.Parse(Console.ReadLine()); newDroid.addAstromechDroid(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected, fireExtingSelected, numOfChips); // adds user input newDroid.saveDroidList(); // saves user input Astromech astromechCost = new Astromech(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected, fireExtingSelected, numOfChips); //creates new astromech object so we can you the methods eith n that class astromechCost.CalculateBaseCost(); // Calculate methods from astromech astromechCost.CalculateTotalCost(); } else { Console.WriteLine(userInput +" Is Not an Option"); Console.WriteLine("------------"); } } //Print save file else if (userInput == "p") { newDroid.PrintSDroidList(); } } }
private void addDroidUI(List<Droid> droid, DroidCollection droidCollection) { List<string> parameters = new List<string>(); int droidtype; string tools,arm,connection; string trash,vacuum,fire; //Get the color, and material Console.Write("Select a Material (default 1.Plastic):\n1.Plastic (20)\n2.Metal(40)\n"); string material = Console.ReadLine(); if (material == "2") material = "Metal"; else material = "Plastic"; parameters.Add (material); Console.Write("Select a Color (default 1.Silver):\n1.Silver\n2.Black\n"); string color = Console.ReadLine(); if (color == "1") color = "Silver"; else color = "Black"; parameters.Add(color); //Print the Droid models Console.WriteLine("Please select a number for Droid type"); Console.WriteLine("1 : Protocol Droid"); Console.WriteLine("2 : Utility Droid"); Console.WriteLine("3 : Janitor Droid"); Console.WriteLine("4 : Astromech Droid\n"); string droidSelection = Console.ReadLine (); //Check which droid was selected by the user and ask for options switch (droidSelection) { case "1": Console.WriteLine ("Protocol Droid Selected"); droidtype = 1; parameters.Add ("Protocol"); Console.WriteLine ("Enter the number of languages"); string languages = Console.ReadLine (); parameters.Add (languages); droidCollection.addDroid(droid, droidtype,parameters); break; case "2": Console.WriteLine ("Utility Droid Selected"); droidtype = 2; parameters.Add ("Utility"); Console.WriteLine ("Toolbox?(1:yes/2:no)"); tools = Console.ReadLine (); if (tools == "yes" || tools == "1") tools = "1"; else tools = "2"; parameters.Add (tools); Console.WriteLine ("Computer Connection?(1:yes/2:no)"); connection = Console.ReadLine (); if (connection == "yes" || connection == "1") connection = "1"; else connection = "2"; parameters.Add (connection); Console.WriteLine ("arm?(1:yes/2:no)"); arm = Console.ReadLine (); if (arm == "yes" || arm == "1") arm = "1"; else arm = "2"; parameters.Add(arm); droidCollection.addDroid(droid, droidtype,parameters); break; case "3": Console.WriteLine ("Janitor Droid Selected"); droidtype = 3; parameters.Add ("Janitor"); Console.WriteLine ("Toolbox?(1:yes/2:no)"); tools = Console.ReadLine (); if (tools == "yes" || tools == "1") tools = "1"; else tools = "2"; parameters.Add (tools); Console.WriteLine ("Computer Connection?(1:yes/2:no)"); connection = Console.ReadLine (); if (connection == "yes" || connection == "1") connection = "1"; else connection = "2"; parameters.Add (connection); Console.WriteLine ("arm?(1:yes/2:no"); arm = Console.ReadLine (); if (arm == "yes" || arm == "1") arm = "1"; else arm = "2"; parameters.Add (arm); Console.WriteLine ("Trash Compactor?(1:yes/2:no)"); trash = Console.ReadLine (); if (trash == "yes" || trash == "1") trash = "1"; else trash = "2"; parameters.Add (trash); Console.WriteLine ("Vacuum?(1:yes/2:no)"); vacuum = Console.ReadLine (); if (vacuum == "yes" || vacuum == "1") vacuum = "1"; else vacuum = "2"; parameters.Add(vacuum); droidCollection.addDroid(droid, droidtype,parameters); break; case "4": Console.WriteLine ("Astromech Droid Selected"); droidtype = 4; parameters.Add ("Astromech"); Console.WriteLine ("Toolbox?(1:yes/2:no)"); tools = Console.ReadLine (); if (tools == "yes" || tools == "1") tools = "1"; else tools = "2"; parameters.Add (tools); Console.WriteLine ("Computer Connection?(1:yes/2:no)"); connection = Console.ReadLine (); if (connection == "yes" || connection == "1") connection = "1"; else connection = "2"; parameters.Add (connection); Console.WriteLine ("arm?(1:yes/2:no)"); arm = Console.ReadLine (); if (arm == "yes" || arm == "1") arm = "1"; else arm = "2"; parameters.Add (arm); Console.WriteLine ("Fire Extinquisher?(1:yes/2:no)"); fire = Console.ReadLine(); if (fire == "yes" || fire == "1") fire = "1"; else fire = "2"; parameters.Add(fire); Console.WriteLine("how many per ship?"); parameters.Add(Console.ReadLine()); droidCollection.addDroid(droid, droidtype,parameters); break; } }
static void Main(string[] args) { //Variables to be used throughout String model = String.Empty; String material = String.Empty; String color = String.Empty; Boolean toolbox = false; Boolean computerConnection = false; Boolean arm = false; Boolean trashCompactor = false; Boolean vacuum = false; Boolean fireExtinquisher = false; Int32 numberShips = 0; //Constant size for the Droid Collection const Int32 DROID_COLLECTION_SIZE = 100; //Create an instance of the UserInterface and DroidCollection classes UserInterface userInterface = new UserInterface(); DroidCollection droidCollection = new DroidCollection(DROID_COLLECTION_SIZE); //Prompt for user input. Int32 choice1 = userInterface.FirstMenu(); Int32 type; //While the user has not chosen to exit the program. while (choice1 != 3) { //If the user has chosen to ADD a Droid. if (choice1 == 1) { type = userInterface.BeginBuild(); material = userInterface.MaterialOption(); color = userInterface.ColorOption(); switch (type) { case 1: { model = "Protocol"; Int32 languages = userInterface.ProtocolNumberLanguages(); droidCollection.NewDroid(model, material, color, languages); userInterface.DroidAddSuccess(); break; } case 2: { model = "Utility"; toolbox = userInterface.UtilityToolbox(); computerConnection = userInterface.UtilityComputerConnection(); arm = userInterface.UtilityArm(); droidCollection.NewDroid(model, material, color, toolbox, computerConnection, arm); userInterface.DroidAddSuccess(); break; } case 3: { model = "Janitor"; toolbox = userInterface.UtilityToolbox(); computerConnection = userInterface.UtilityComputerConnection(); arm = userInterface.UtilityArm(); trashCompactor = userInterface.JanitorTrashCompactor(); vacuum = userInterface.JanitorVacuum(); droidCollection.NewDroid(model, material, color, toolbox, computerConnection, arm, trashCompactor, vacuum); userInterface.DroidAddSuccess(); break; } case 4: { model = "Astromech"; toolbox = userInterface.UtilityToolbox(); computerConnection = userInterface.UtilityComputerConnection(); arm = userInterface.UtilityArm(); fireExtinquisher = userInterface.AstromechFireExtinquisher(); numberShips = userInterface.AstromechNumberShips(); droidCollection.NewDroid(model, material, color, toolbox, computerConnection, arm, fireExtinquisher, numberShips); userInterface.DroidAddSuccess(); break; } } } //If the user has chosen to PRINT the Droid list. if (choice1 == 2) { string[] allDroids = droidCollection.AquireAllDroids(); if (allDroids.Length > 0) { userInterface.DisplayAllDroids(allDroids); } else { userInterface.DisplayNoDroidsError(); } } //Prompt the user to make a choice from the first menu again. choice1 = userInterface.FirstMenu(); } }
/// <summary> /// Creates new android list and removes all information pertaining to old one. /// </summary> private void ResetList() { UserInterface.ClearDisplayLine(); UserInterface.ClearList(); droidCollection = new DroidCollection(); }
static void Main(string[] args) { // Create class instances UserInterface ui = new UserInterface(); //Array IDroid[] droidList = new IDroid[20]; DroidCollection droidCollect = new DroidCollection(); int length = 0; string output = ""; //I dont think I needed this, but I was getting some weird formatting issues intially Console.BufferHeight = 1000; //Header (cause console programs are boring) ui.Output("************************************************************" + Environment.NewLine + "********* CIS237 *********" + Environment.NewLine + "******** Assignment #3 ********" + Environment.NewLine + "******* Jawa Inventory Managment *******" + Environment.NewLine + "************************************************************" + Environment.NewLine); //Return tag MenuReturn: int choice = ui.GetMainInput(); //Keep running menu untill user exits while (choice != 3) { //****************************************** //Print option //****************************************** if (choice == 1) { Console.Clear(); foreach (IDroid droid in droidList) { if (droid != null) { output += droid.ToString(); } } Console.WriteLine(output); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); Console.Clear(); goto MenuReturn; } //**************************************** //Add Droid Option //**************************************** if (choice == 2) { Console.Clear(); droidCollect.AddDroid(droidList, length); length++; Console.WriteLine(""); Console.WriteLine("Complete! Press any key to continue..."); Console.ReadKey(); Console.Clear(); goto MenuReturn; } Environment.Exit(0); } }
// Constructor for the AddDroid class: public AddDroid(DroidCollection droidCollection) { // Declare variables and set blank for error checking purposes: string model = ""; string materialType = ""; string colorChoice = ""; // While the model is still blank: while (model == "") { // Prompt for model type: Console.WriteLine(); Console.WriteLine("Current options for model are Protocol, Utility, Janitor and Astromech."); Console.Write("Please enter the model type: "); // Save model type: model = Console.ReadLine(); // Check for correct spelling - allows for any casing and extra spacing: if (!model.ToUpper().Equals("PROTOCOL") && !model.ToUpper().Equals("UTILITY") && !model.ToUpper().Equals("JANITOR") && !model.ToUpper().Equals("ASTROMECH")) { // If spelled wrong, output error message and reset model to blank so the process loops again: Console.WriteLine(); Console.WriteLine("That model was not valid. Please spell the model the same as the option listed."); model = ""; } } // While the material is still blank: while (materialType == "") { // Prompt for material type: Console.WriteLine(); Console.WriteLine("Current options for material are Steel, Aluminum, and Plastic."); Console.Write("Please enter the material type: "); // Save material type: materialType = Console.ReadLine(); // Check for correct spelling - allows for any casing and extra spacing: if (!materialType.ToUpper().Equals("STEEL") && !materialType.ToUpper().Equals("ALUMINUM") && !materialType.ToUpper().Equals("PLASTIC")) { // If spelled wrong, output error message and reset material to blank so the process loops again: Console.WriteLine(); Console.WriteLine("That material type was not valid. Please spell the material the same as the option listed."); materialType = ""; } } // While the model is still blank: while (colorChoice == "") { // Prompt for color: Console.WriteLine(); Console.WriteLine("Current options for color are Red, Blue, and Gray."); Console.Write("Please enter the color choice (case sensitive): "); // Save color: colorChoice = Console.ReadLine(); // Check for correct spelling - allows for any casing and extra spacing: if (!colorChoice.ToUpper().Equals("RED") && !colorChoice.ToUpper().Equals("BLUE") && !colorChoice.ToUpper().Equals("GRAY")) { // If spelled wrong, output error message and reset color to blank so the process loops again: Console.WriteLine(); Console.WriteLine("That color was not valid. Please spell the color name the same as the option listed."); colorChoice = ""; } } // Enter switch statement to check the model type and continue questions by group: switch (model.ToUpper()) { // If the model type is Protocol: case "PROTOCOL": // Declare a variable to hold the # of languages and initialize to -1 for error checking: int numberOfLanguages = -1; // While the # of languages is less than 0 (an invalid option): while (numberOfLanguages < 0) { // Prompt user for input: Console.WriteLine(); Console.Write("Please enter the number of languages known (e.g. 0, 1, 2): "); // Try to parse the input as an integer and save to the variable, must be >= 0: // (setting the numberOfLanguages to a number greater than -1 will also exit the loop) if (Int32.TryParse(Console.ReadLine(), out numberOfLanguages) && numberOfLanguages >= 0) { // Create a new Protocol Droid based on the specifications given: // To make sure that the pricing is completed correctly, put in the model name directly, // and make lowercase and remove spacing from the material and color: droidCollection.add("Protocol", materialType.Trim().ToLower(), colorChoice.Trim().ToLower(), numberOfLanguages); Console.WriteLine(); Console.WriteLine("Droid successfully entered!"); Console.WriteLine(); } else { // Error message if input cannot be parsed as an int: Console.WriteLine("Please enter an integer value only."); // Make sure the loop will continue: numberOfLanguages = -1; } } break; // If the model type is Utility: case "UTILITY": // Call the common utility questions method: UtilityQuestions(); // Call the add method of the DroidCollection class: droidCollection.add("Utility", materialType.Trim().ToLower(), colorChoice.Trim().ToLower(), toolbox, computerConnection, arm); Console.WriteLine(); Console.WriteLine("Droid successfully entered!"); Console.WriteLine(); break; // If the model type is Janitor: case "JANITOR": // Call the common utility questions method: UtilityQuestions(); // Janitor specific questions - prompt user for input, if y or Y, save the // corresponding variable as true, else false: Console.WriteLine(); Console.Write("Does the droid have a trash compactor (Y for yes) ? "); bool trash; if (Console.ReadLine().ToUpper() == "Y") { trash = true; } else { trash = false; } Console.WriteLine(); Console.Write("Does the droid have a vacuum (Y for yes) ? "); bool vacuum; if (Console.ReadLine().ToUpper() == "Y") { vacuum = true; } else { vacuum = false; } // Call the add method of the DroidCollection class: droidCollection.add("Janitor", materialType.Trim().ToLower(), colorChoice.Trim().ToLower(), toolbox, computerConnection, arm, trash, vacuum); Console.WriteLine(); Console.WriteLine("Droid successfully entered!"); Console.WriteLine(); break; // If the model type is Astromech: case "ASTROMECH": // Call the common utility questions method: UtilityQuestions(); // Astromech-specific questions - prompt for user input, y or Y to save as true, else false: Console.WriteLine(); Console.Write("Does the droid have a fire extinguisher (Y for yes) ? "); bool fire; if (Console.ReadLine().ToUpper() == "Y") { fire = true; } else { fire = false; } // Variable for number of ships, set to -1 for error checking: int ships = -1; // While the number of ships is >= 0: while (ships < 0) { // Prompt for input: Console.WriteLine(); Console.Write("Please enter the number of ships: "); // Attempt to parse to int and save to the variable: if (Int32.TryParse(Console.ReadLine(), out ships)) { // If it works, call the add method of the DroidCollection class: droidCollection.add("Astromech", materialType.Trim().ToLower(), colorChoice.Trim().ToLower(), toolbox, computerConnection, arm, fire, ships); Console.WriteLine(); Console.WriteLine("Droid successfully entered!"); Console.WriteLine(); } else { // If the input is not an int, output error to user and reset ships to -1 so loop continues: Console.WriteLine(); Console.WriteLine("The number of ships must be an integer."); ships = -1; } } break; default: // Error message for invalid model: Console.WriteLine("You did not enter a valid model."); break; } }
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(); }
private void addDroidUI(List <Droid> droid, DroidCollection droidCollection) { List <string> parameters = new List <string>(); int droidtype; string tools, arm, connection; string trash, vacuum, fire; //Get the color, and material Console.Write("Select a Material (default 1.Plastic):\n1.Plastic (20)\n2.Metal(40)\n"); string material = Console.ReadLine(); if (material == "2") { material = "Metal"; } else { material = "Plastic"; } parameters.Add(material); Console.Write("Select a Color (default 1.Silver):\n1.Silver\n2.Black\n"); string color = Console.ReadLine(); if (color == "1") { color = "Silver"; } else { color = "Black"; } parameters.Add(color); //Print the Droid models Console.WriteLine("Please select a number for Droid type"); Console.WriteLine("1 : Protocol Droid"); Console.WriteLine("2 : Utility Droid"); Console.WriteLine("3 : Janitor Droid"); Console.WriteLine("4 : Astromech Droid\n"); string droidSelection = Console.ReadLine(); //Check which droid was selected by the user and ask for options switch (droidSelection) { case "1": Console.WriteLine("Protocol Droid Selected"); droidtype = 1; parameters.Add("Protocol"); Console.WriteLine("Enter the number of languages"); string languages = Console.ReadLine(); parameters.Add(languages); droidCollection.addDroid(droid, droidtype, parameters); break; case "2": Console.WriteLine("Utility Droid Selected"); droidtype = 2; parameters.Add("Utility"); Console.WriteLine("Toolbox?(1:yes/2:no)"); tools = Console.ReadLine(); if (tools == "yes" || tools == "1") { tools = "1"; } else { tools = "2"; } parameters.Add(tools); Console.WriteLine("Computer Connection?(1:yes/2:no)"); connection = Console.ReadLine(); if (connection == "yes" || connection == "1") { connection = "1"; } else { connection = "2"; } parameters.Add(connection); Console.WriteLine("arm?(1:yes/2:no)"); arm = Console.ReadLine(); if (arm == "yes" || arm == "1") { arm = "1"; } else { arm = "2"; } parameters.Add(arm); droidCollection.addDroid(droid, droidtype, parameters); break; case "3": Console.WriteLine("Janitor Droid Selected"); droidtype = 3; parameters.Add("Janitor"); Console.WriteLine("Toolbox?(1:yes/2:no)"); tools = Console.ReadLine(); if (tools == "yes" || tools == "1") { tools = "1"; } else { tools = "2"; } parameters.Add(tools); Console.WriteLine("Computer Connection?(1:yes/2:no)"); connection = Console.ReadLine(); if (connection == "yes" || connection == "1") { connection = "1"; } else { connection = "2"; } parameters.Add(connection); Console.WriteLine("arm?(1:yes/2:no"); arm = Console.ReadLine(); if (arm == "yes" || arm == "1") { arm = "1"; } else { arm = "2"; } parameters.Add(arm); Console.WriteLine("Trash Compactor?(1:yes/2:no)"); trash = Console.ReadLine(); if (trash == "yes" || trash == "1") { trash = "1"; } else { trash = "2"; } parameters.Add(trash); Console.WriteLine("Vacuum?(1:yes/2:no)"); vacuum = Console.ReadLine(); if (vacuum == "yes" || vacuum == "1") { vacuum = "1"; } else { vacuum = "2"; } parameters.Add(vacuum); droidCollection.addDroid(droid, droidtype, parameters); break; case "4": Console.WriteLine("Astromech Droid Selected"); droidtype = 4; parameters.Add("Astromech"); Console.WriteLine("Toolbox?(1:yes/2:no)"); tools = Console.ReadLine(); if (tools == "yes" || tools == "1") { tools = "1"; } else { tools = "2"; } parameters.Add(tools); Console.WriteLine("Computer Connection?(1:yes/2:no)"); connection = Console.ReadLine(); if (connection == "yes" || connection == "1") { connection = "1"; } else { connection = "2"; } parameters.Add(connection); Console.WriteLine("arm?(1:yes/2:no)"); arm = Console.ReadLine(); if (arm == "yes" || arm == "1") { arm = "1"; } else { arm = "2"; } parameters.Add(arm); Console.WriteLine("Fire Extinquisher?(1:yes/2:no)"); fire = Console.ReadLine(); if (fire == "yes" || fire == "1") { fire = "1"; } else { fire = "2"; } parameters.Add(fire); Console.WriteLine("how many per ship?"); parameters.Add(Console.ReadLine()); droidCollection.addDroid(droid, droidtype, parameters); break; } }
/// <summary> /// ***********Problems*********** /// Dosen't save to file or print from file correctly /// Not sure if im useing calculate methods from othe classes right /// No UI, Will work before next assgnment /// Not a lot or very detail comment(have to get used to commenting while i code) /// /// </summary> /// <param name="args"></param> static void Main(string[] args) { //Variables string materialSelected = string.Empty; string modelSelected; string colorSelected; bool toolboxSelected; bool computerConnectionSelected; bool armSelected; bool trashCompatSelected; bool vacuumSelected; bool fireExtingSelected; int numOfChips; int numberOfLanguage; string userInput = string.Empty; DroidCollection newDroid = new DroidCollection(); // Console.Write("It Still Runs!!!!!!!!!!!"); while (userInput != "e") { Console.WriteLine("Type n to add a new droid"); Console.WriteLine("Type p to print droid"); Console.WriteLine("Type e to exit"); Console.Write("Select an opetion: "); userInput = Console.ReadLine(); Console.WriteLine("----------------"); if (userInput == "n") { // All droid Units go throuh this procees Console.WriteLine("--------------------"); Console.Write("Material: "); materialSelected = Console.ReadLine(); Console.Write("Model: "); modelSelected = Console.ReadLine(); Console.Write("Color: "); colorSelected = Console.ReadLine(); Console.Write("Droid Model: "); Console.WriteLine("Protocol, Utility, Janitor, Astromech"); Console.WriteLine("selcet a Droid"); userInput = Console.ReadLine(); //if protocol is selceted if (userInput.Equals("protocol", StringComparison.OrdinalIgnoreCase)) { Console.Write("Number of Language: "); numberOfLanguage = Int32.Parse(Console.ReadLine()); newDroid.addProtocolDroid(materialSelected, modelSelected, colorSelected, numberOfLanguage); // adds user input newDroid.saveDroidList(); // saves user input Console.WriteLine("------------------"); } // if utility is selected else if (userInput.Equals("utility", StringComparison.OrdinalIgnoreCase)) { Console.Write("Tool box yes or no "); toolboxSelected = ToBool(Console.ReadLine()); Console.Write("Computer Connection yes or no "); computerConnectionSelected = ToBool(Console.ReadLine()); Console.Write("Arm yes or no "); armSelected = ToBool(Console.ReadLine()); newDroid.addUtilityDroid(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected); // adds user input newDroid.saveDroidList(); // saves user input } // if janitor is selected else if (userInput.Equals("janitor", StringComparison.OrdinalIgnoreCase)) { Console.Write("Tool box yes or no "); toolboxSelected = ToBool(Console.ReadLine()); Console.Write("Computer Connection yes or no "); computerConnectionSelected = ToBool(Console.ReadLine()); Console.Write("Arm yes or no "); armSelected = ToBool(Console.ReadLine()); Console.Write("Trash Compactoer yes or no "); trashCompatSelected = ToBool(Console.ReadLine()); Console.Write("Vacuum yes or no "); vacuumSelected = ToBool(Console.ReadLine()); newDroid.addJanitorDroid(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected, trashCompatSelected, vacuumSelected); // adds user input newDroid.saveDroidList(); // saves user input Janitor janitorCost = new Janitor(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected, trashCompatSelected, vacuumSelected); //creates new Janitor object so we can you the methods eith n that class janitorCost.CalculateBaseCost(); // Calculate methods from astromech janitorCost.CalculateTotalCost(); } //If astromec is selected else if (userInput.Equals("astromech", StringComparison.OrdinalIgnoreCase)) { Console.Write("Tool box yes or no "); toolboxSelected = ToBool(Console.ReadLine()); Console.Write("Computer Connection yes or no "); computerConnectionSelected = ToBool(Console.ReadLine()); Console.Write("Arm yes or no "); armSelected = ToBool(Console.ReadLine()); Console.Write("FireExtingquisher yes or no "); fireExtingSelected = ToBool(Console.ReadLine()); Console.Write("Number of Chips "); numOfChips = Int32.Parse(Console.ReadLine()); newDroid.addAstromechDroid(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected, fireExtingSelected, numOfChips); // adds user input newDroid.saveDroidList(); // saves user input Astromech astromechCost = new Astromech(materialSelected, modelSelected, colorSelected, toolboxSelected, computerConnectionSelected, armSelected, fireExtingSelected, numOfChips); //creates new astromech object so we can you the methods eith n that class astromechCost.CalculateBaseCost(); // Calculate methods from astromech astromechCost.CalculateTotalCost(); } else { Console.WriteLine(userInput + " Is Not an Option"); Console.WriteLine("------------"); } } //Print save file else if (userInput == "p") { newDroid.PrintSDroidList(); } } }
public static UIMenu AstromechDroidMenu = new UIMenu(); // Astromech Droid Menu static void Main(string[] args) { // Populate menus populateMenus(); // Initialize the console window UserInterface.InitializeConsoleWindow("Droid Creator"); // Main program loop do { // Print the main menu and get an answer from the user int menuChoice = UserInterface.GetMainMenuSelection(MenuSelections, "Droid Making Program"); // Make a choice depending on the menu selection switch (menuChoice) { // Add a droid case 1: // General pattern here is 1) draw the menu 2) declare value variables 3) get the values from the menu elements and assign them to the value variables // Variable to hold the new droid Droid assembledDroid = null; #region Droid Variables // Variables to hold values that will be used to create a new droid Droid.DroidMaterial material = Droid.DroidMaterial.AGRINIUM; Droid.DroidColor color = Droid.DroidColor.BLACK; Droid.DroidModel model = Droid.DroidModel.ASTROMECH; int numberOfLanguages = 0; bool hasToolbox = false; bool hasComputerConnection = false; bool hasArm = false; bool hasTrashCompactor = false; bool hasVacuum = false; bool hasFireExtinguisher = false; int numberOfShips = 0; #endregion // Start menu GeneralDroidMenu.Start(); #region General Droid Handling // Get handle to UI elements SelectionBox materialBox = (SelectionBox)GeneralDroidMenu.GetElementByTitle("material:"); SelectionBox colorBox = (SelectionBox)GeneralDroidMenu.GetElementByTitle("color:"); SelectionBox modelBox = (SelectionBox)GeneralDroidMenu.GetElementByTitle("model:"); // Extract and assign data from elements Enum.TryParse <Droid.DroidMaterial>(materialBox.SelectedText, out material); Enum.TryParse <Droid.DroidColor>(colorBox.SelectedText, out color); Enum.TryParse <Droid.DroidModel>(modelBox.SelectedText, out model); #endregion #region Protocol and Utility Droid Handling // Decide which menu to show next based on what they entered for "model" switch (model) { case Droid.DroidModel.PROTOCOL: // For the protocol droid... // Start the menu ProtocolDroidMenu.Start(); // Get handle to UI element SelectionBox numLanguagesBox = (SelectionBox)ProtocolDroidMenu.GetElementByTitle("number of languages:"); // Extract and assign data from element int.TryParse(numLanguagesBox.SelectedText, out numberOfLanguages); break; case Droid.DroidModel.UTILITY: // For the utility, janitor, and astromech droids... case Droid.DroidModel.JANITOR: case Droid.DroidModel.ASTROMECH: // Start the menu UtilityDroidMenu.Start(); // Get handle to UI elements SelectionBox hasToolboxBox = (SelectionBox)UtilityDroidMenu.GetElementByTitle("toolbox:"); SelectionBox hasComputerConnectionBox = (SelectionBox)UtilityDroidMenu.GetElementByTitle("computer connection:"); SelectionBox hasArmBox = (SelectionBox)UtilityDroidMenu.GetElementByTitle("arm:"); // Extract and assign data from elements bool.TryParse(hasToolboxBox.SelectedText, out hasToolbox); bool.TryParse(hasComputerConnectionBox.SelectedText, out hasComputerConnection); bool.TryParse(hasArmBox.SelectedText, out hasArm); #region Janitor and Astromech Droid Handling // Take care of the janitor and astromech droids switch (model) { case Droid.DroidModel.JANITOR: // For the janitor droid... // Start the menu JanitorDroidMenu.Start(); // Get handle to UI elements SelectionBox hasTrashCompactorBox = (SelectionBox)JanitorDroidMenu.GetElementByTitle("trash compactor:"); SelectionBox hasVacuumBox = (SelectionBox)JanitorDroidMenu.GetElementByTitle("vacuum:"); // Extract and assign data from elements bool.TryParse(hasTrashCompactorBox.SelectedText, out hasTrashCompactor); bool.TryParse(hasVacuumBox.SelectedText, out hasVacuum); break; case Droid.DroidModel.ASTROMECH: // For the astromech droid... // Start the menu AstromechDroidMenu.Start(); // Get handle to UI elements SelectionBox hasFireExtinguisherBox = (SelectionBox)AstromechDroidMenu.GetElementByTitle("fire extinguisher:"); SelectionBox numberOfShipsBox = (SelectionBox)AstromechDroidMenu.GetElementByTitle("number of ships:"); // Extract and assign data from elements bool.TryParse(hasFireExtinguisherBox.SelectedText, out hasFireExtinguisher); int.TryParse(numberOfShipsBox.SelectedText, out numberOfShips); break; } #endregion break; } #endregion // Based on what the user entered, create a new droid from that data switch (model) { case Droid.DroidModel.PROTOCOL: assembledDroid = new ProtocolDroid(material, model, color, numberOfLanguages); break; case Droid.DroidModel.UTILITY: assembledDroid = new UtilityDroid(material, model, color, hasToolbox, hasComputerConnection, hasArm); break; case Droid.DroidModel.JANITOR: assembledDroid = new JanitorDroid(material, model, color, hasToolbox, hasComputerConnection, hasArm, hasTrashCompactor, hasVacuum); break; case Droid.DroidModel.ASTROMECH: break; } // FINALLY, add the assembled droid to the list DroidCollection.Add(assembledDroid); // Clear screen UserInterface.ClearScreen(); // Draw status UserInterface.SetStatus(UserInterface.PressAnyPhrase(assembledDroid.Model + " droid added to droid list!")); // Wait for user to press a key Console.ReadKey(true); break; // List the droids case 2: UserInterface.ListDroids(); break; // Exit program case 3: System.Environment.Exit(0); break; } } while (true); }