//main menu used to start the program public void StartMenu() { while (DSelect != 1 || DSelect != 2 || DSelect != 3 || DSelect != 4 || DSelect != 5) { Console.WriteLine("Project # 3"); Console.WriteLine("-------------------------"); Console.WriteLine("1 - Add a Droid"); Console.WriteLine("2 - Sort Droids by Model"); Console.WriteLine("3 - Sort Droids by Total Cost"); Console.WriteLine("4 - Print List of droids"); Console.WriteLine("5 - Exit"); Console.Write(""); try { DSelect = int.Parse(Console.ReadLine()); Console.WriteLine(); //adds droid if (DSelect == 1) { AddDroid(); } //sorts droids by model if (DSelect == 2) { try { //calls bucketsort droidCollection.BucketSort(); Console.WriteLine("Droids sorted by Model Press 4 to view list"); Console.WriteLine(); } catch { //catch errors Console.WriteLine("Error Sort failed"); } } //sorts droids by price if (DSelect == 3) { try { //calls merge sort droidCollection.MergeSort(); Console.WriteLine("Droids sorted by Price Press 4 to view lsit"); Console.WriteLine(); } catch { //catch errors Console.WriteLine("Error Sort failed"); } } //prints list of droids if (DSelect == 4) { PrintList(); } //exits program if (DSelect == 5) { Environment.Exit(0); } } //catch invalid input catch { Console.WriteLine(); Console.WriteLine("Error: Please make a proper selection"); } } }
//*********************MAIN MENU METHOD**************************// public void MainMenu() { Console.WriteLine("Welcome to the Jawas on Tatooine Droid Program\n"); AddDummyData(); //Call method to add hard-coded dummy data to DroidCollection while (menuSelection != 1 || menuSelection != 2 || menuSelection != 3 || menuSelection != 4 || menuSelection != 5 || menuSelection != 6) { Console.WriteLine("Main Menu\n"); Console.WriteLine("1 - Add Droid"); Console.WriteLine("2 - Sort Droid List By Model"); Console.WriteLine("3 - Sort Droid List By Total Cost"); Console.WriteLine("4 - Print Current Droid List"); Console.WriteLine("5 - Reset Droid List: Populates List With Random Droids For Testing"); Console.WriteLine("6 - Exit\n"); Console.Write("Enter Number: "); try { menuSelection = int.Parse(Console.ReadLine()); Console.WriteLine(); if (menuSelection == 1) { AddDroid(); } if (menuSelection == 2) { try { droidCollection.BucketSort(); //This line will call the bucket sort method from the droid collection class, and sort the droid list by Model. Console.WriteLine("Sort Successful, Press 4 To See Sorted Droid List\n"); } catch { Console.WriteLine("Sort Unsuccessful\n"); } } if (menuSelection == 3) { try { droidCollection.MergeSort(); //This line will call the merge sort method from the droid collection class, and sort the droid list by Total Cost. Console.WriteLine("Sort Successful, Press 4 To See Sorted Droid List\n"); } catch { Console.WriteLine("Sort Unsuccessful\n"); } } if (menuSelection == 4) { PrintDroidList(); } if (menuSelection == 5) { ResetList(); } if (menuSelection == 6) { Environment.Exit(0); } if (menuSelection > 6 || menuSelection < 1) { Console.WriteLine("Input Must Be Integer Between 1 - 6\n"); } } catch { Console.WriteLine(); Console.WriteLine("Input Error\n"); } } }