Question: (5 pts) Implement code in C#. XYZ Company uses the service provided by an obtained object of Utility class to sort elements of type T.

(5 pts) Implement code in C#. XYZ Company uses the service provided by an obtained object of Utility class to sort elements of type T. The default constructor of the Utility class will set the private string attribute sortName to be bubblesort algorithm. For other sorting algorithms like quicksort, the constructor Utility(string sortName) needs to be used instead. Note that new sorting algorithms are likely to be added in the future. The Utility class has two methods. One method can return the sortName and the other method List sort(List data) can sort objects of type T ascendingly based on the price of T. Besides the price attribute, class T has two other attributes: ID and name. All except ID are accessible through the individual get/set methods. The ID is expected to be fixed once assigned. The two current sorting algorithms cannot print the sorted result but only return the sorted list for objects of type T. The XYZ Company now demands this printing feature to have add-ons for the two existing algorithms and possibly new algorithms as well. To prevent troubles, the goal is not to modify the algorithm code, not to change the relationship between XYZ, and not to update the existing Utility class. Moreover, the add-ons for each algorithm should allow the printing features in its own way. The bubblesort will print ID, name and price on a row in order, while the quicksort will print price, name and then ID in a different order.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!