Question: Sort by Grade Given a List of Student objects named students and a Comparator called gradeComparator , sort each student by their grade ( highest
Sort by Grade
Given a List ofStudentobjects namedstudentsand a Comparator calledgradeComparator sort each student by their grade highest grades first
Note:
Use thesortmethod to compare the students' grades.
In the parameters of thesortmethod compare students using thegradeComparator
import java.io;
import java.util.;
public class Student
private String name;
private int grade;
public StudentString name, int grade
this.name name;
this.grade grade;
public String getName
return this.name;
public int getGrade
return this.grade;
public static void mainString args
List students new ArrayList;
students.addnew StudentAlice;
students.addnew StudentRob;
students.addnew StudentCharlie;
students.addnew StudentJanice;
students.addnew StudentEva;
Comparator gradeComparator Comparator.comparingIntStudent::getGrade;
DO NOT CHANGE THE CODE ABOVE THIS LINE
WRITE YOUR CODE HERE
DO NOT CHANGE THE CODE BELOW THIS LINE
for Student s : students
System.out.printlnsgetName Grade: sgetGrade;
Expected STDOUT
CharlieGrade:
AliceGrade:
JaniceGrade:
RobGrade:
EvaGrade:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
