Question: C# Programming Platform II Sorting Basics Assignment Step 1: Create a console application named yourname_sortingbasics. Step 2: Create a Student class that has the following:
C# Programming Platform II Sorting Basics Assignment Step 1: Create a console application named yourname_sortingbasics. Step 2: Create a Student class that has the following: a. StudentID, LastName, FirstName, CourseID and Course Grade properties. b. A constructor that collects the above property information. c. A method that retrieves test data for this Student class. This method will use the following code for testing purposes: public static List getTestStudents() { // For testing purposes some duplicate student infomation will be used. List students = new List(); students.Add(new Student(1, "Jones", "Joan", "art0024", 3.0)); students.Add(new Student(2, "Einstein", "Jose", "math0001", 3.3)); students.Add(new Student(5, "Gonzales", "Miranda", "cs0024", 2.7)); students.Add(new Student(4, "Lee", "Kim", "bs0024", 2.7)); students.Add(new Student(3, "Jaspers", "Rachel", "cs0001", 2.7)); students.Add(new Student(6, "gates", "Bill", "cs0001", 4.0)); students.Add(new Student(6, "Gates", "Bill", "art0024", 3.0)); students.Add(new Student(6, "Gates", "bill", "art0024", 1.0)); students.Add(new Student(7, "Allison", "George", "math0023", 2.7)); students.Add(new Student(7, "Allison", "Alice", "cs0001", 2.7)); students.Add(new Student(8, "Sills", "Carol", "cs0001", 1.7)); students.Add(new Student(8, "Sills", "Albert", "cs0001", 2.7)); students.Add(new Student(9, "Starr", "Bert", "chem0020", 3.7)); return students; } d. Override the ToString method to dump out the current student test data situation (data will sometimes be not sorted and then sorted various ways). e. Support methods for adding a sort title and column headers for a report on your student data. These methods will be used to display student data before and after various sorting conditions. Your data should be displayed something like this: Step 3: In your main method test your Employee class with the following code: List students = Student.getTestStudents(); Console.WriteLine(Student.SortTitle("Not Sorted")); Console.WriteLine(Student.ColumnHeader()); foreach (Student student in students) { Console.WriteLine(student); } Console.WriteLine(" Press to quit..."); Console.ReadKey(); You should see a data dump on the test student data similar to the following: Note: Google string format operations to see what options you have in terms of using right hand justification, left hand justification, PadLeft, PadRight, etc. Step 4: Modify your Student class to add a default last name, first name sort capability. The IComparable interface is used typically to compare the current class instance with other instances of the same type. To use this technique, you would add to the Student class the IComparable interface: public class Student : IComparable The compiler will then warn you that you need to implement the interface member CompareTo. Now implement the CompareTo method to allow sorting by last name and then first name. Note: when doing name comparisons you usually uppercase all of the string characters first before processing the sort options. Thus make sure you UpperCase first and last name so that no sort differences with occur based on case differences. Bill Gates versus bill Gates or bill gates. 10 points are scored if you correctly implement the CompareTo method to provide this last name, first name sort capability. To test your CompareTo method in your main method add the following code: // Sort using built in Student IComparer default sort... Console.WriteLine(Student.SortTitle("Sorted by Last Name and First Name Sorted Using Built in IComparable")); Console.WriteLine(Student.ColumnHeader()); students.Sort(); foreach (Student s in students) { Console.WriteLine(s); } Your console screen should then show the following: Note: Original data is preserved. However, you can output upper cased string data if you wish. Step 5: Now lets examine the common situation of multiple sorts done on multiple sort fields. The IComparer interface is used when you want to compare 2 objects of the same type. It can be implemented with nested classes or separate external classes. As an example lets set up a separate class called StuSortCourseGradeLastFirst that provides sorting capability on course grade, then last name and first name: Points scored for implementing correctly a sort by course grade, last name and then first name: 10 points To test this sort add the following code to your Main method: Console.WriteLine(Student.SortTitle("Sorted by Course Grade, Last Name, and then First Name Using IComparer")); Console.WriteLine(Student.ColumnHeader()); students.Sort(new StuSortCourseGradeLastFirst()); foreach (Student s in students) { Console.WriteLine(s); } Step 6: Now lets sort your students by Last Name, First Name and then CourseID with another sort class such as StuSortLastFirstCourseIDCourseGrade.