Question: **Java programming language Question 2: (a) Complete the code hereafter using the strategy pattern to implement a StudentList class that allows sorting via the SortStrategy
**Java programming language
Question 2:
(a) Complete the code hereafter using the strategy pattern to implement a StudentList class that allows sorting via the SortStrategy interface. (Keep it simple; do not write code other than needed to realize the strategy pattern.) Then add the code in the main() that will create a StudentList object from a given ArrayList aList, change its default sorting strategy, and sort its data. (4 marks)
public interface SortStrategy {
int sort( ArrayList list );
}
public class BSort implements SortStrategy {
public int sort( ArrayList list ) {
System.out.println("Using B-sort :"); /* */ }
}
public class ISort implements SortStrategy {
public int sort( ArrayList list ) { System.out.println("Using I-sort :"); /* */ }
}
public class StudentList {
private ArrayList listData; public StudentList ( ArrayList listData )
(b) Draw a UML class diagram showing the StudentList class and all the interfaces. Name the class relationship shown between the class and the interface, and give a simple usage scenario to justify it. (3 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
