} // end Main /// <summary> /// Method that is called in the main method so the user can decide how they want the employee list sorted by /// </summary> /// <param name="payableObjects">An IPayable object list which contains an employee list</param> public static void Menu(IPayable[] payableObjects) { string option; bool cont = true; while (cont) { Console.WriteLine("Please input [1-4]: "); Console.WriteLine("[1] Sort last name in descending order using IComparable"); Console.WriteLine("[2] Sort pay amount in ascending order using IComparer"); Console.WriteLine("[3] Sort by Social Security number in descending order using a selection sort and delegate"); Console.WriteLine("[4] Sorting last name in ascending order and pay amount in descinding order by using LINQ"); option = Console.ReadLine(); if (option == "1") { DescendingOrder(payableObjects); } else if (option == "2") { Console.WriteLine("\nSort by Pay: Ascending Order"); Array.Sort(payableObjects, Employee.SortPayAscending()); foreach (IPayable emp in payableObjects) { Console.WriteLine(emp.ToString() + "\n" + emp.GetPaymentAmount() + "\n"); } } else if (option == "3") { CompareDelegateSSN EmployeeCompareSSN = new CompareDelegateSSN(Employee.sortSSN); SelectionSort(payableObjects, EmployeeCompareSSN); foreach (IPayable emp in payableObjects) { Console.WriteLine(emp.ToString() + "\n"); } } else if (option == "4") { List <Employee> emp = new List <Employee>(); for (int i = 0; i <= 7; i++) { emp.Add((Employee)payableObjects[i]); } var orderByResult = from e in emp orderby e.LastName, e.GetPaymentAmount() descending select e; foreach (var empl in orderByResult) { Console.WriteLine(empl.ToString() + "\n"); } } else { Console.WriteLine("Exiting Out of Application"); cont = false; } } }
/// <summary> /// Method that contains the algorith that aids in sorting employee list with SSN using the Selection sort algorithm /// </summary> /// <param name="arr">list that contains Employee list</param> /// <param name="compSSN">delegate of Class</param> public static void SelectionSort(IPayable[] empl, CompareDelegateSSN compSSN) { int n = empl.Length; for (int i = 0; i < n - 1; i++) { int ind = i; for (int j = i + 1; j < n; j++) { Employee emp1 = (Employee)empl[j]; Employee emp2 = (Employee)empl[ind]; if (compSSN(empl[j], empl[ind]) < 0) { ind = j; } } IPayable temp = empl[ind]; empl[ind] = empl[i]; empl[i] = temp; } }