package test.graderank; import java.util.ArrayList; import java.util.Collections; public class GradeComparison { String name; int maths; int physics; int chemistry; public GradeComparison() { } public GradeComparison(String name, int maths, int physics, int chemistry) { this.name = name; this.maths = maths; this.physics = physics; this.chemistry = chemistry; } GradeComparison[] getRankedResults(ArrayList results) { //Write your code here return null; } // Sample code to test your solution public static void main(String[] args) { try { // Example 1 { ArrayList results = new ArrayList(); results.add(new GradeComparison("Tom", 50, 30, 30)); results.add(new GradeComparison("John", 50, 60, 70)); results.add(new GradeComparison("Mathew", 60, 30, 30)); GradeComparison resultObject = new GradeComparison(); GradeComparison[] result = resultObject.getRankedResults(results); if (result != null) for (int i = 0; i < result.length; i++) { System.out.println(result[i].name); } } // Example 2 { ArrayList results = new ArrayList(); results.add(new GradeComparison("Tom", 50, 40, 30)); results.add(new GradeComparison("John", 50, 60, 70)); results.add(new GradeComparison("Mathew", 60, 30, 30)); GradeComparison resultObject = new GradeComparison(); GradeComparison[] result = resultObject.getRankedResults(results); if (result != null) for (int i = 0; i < result.length; i++) { System.out.println(result[i].name); } } } catch (Exception e) { e.printStackTrace(); } } }