I need help with this assignment (also theres a Student class with getGPA() method). I dont know how to go through with completing this
Complete the Course class by implementing the findStudentHighestGpa() method, which returns the Student object with the highest GPA in the course. Assume that no two students have the same highest GPA.
import java.util.ArrayList;
public class Course {
private ArrayList<Student> roster; // Collection of Student objects
public Course() {
roster = new ArrayList<Student>();
}
public Student findStudentHighestGpa() {
//Type code here
}
public void addStudent(Student s) {
roster.add(s);
}
// main
public static void main(String args[]) {
Course course = new Course();
String first; // first name
String last; // last name
double gpa; // grade point average
first = "Henry";
last = "Nguyen";
gpa = 3.5;
course.addStudent(new Student(first, last, gpa)); // Add 1st student
first = "Brenda";
last = "Stern";
gpa = 2.0;
course.addStudent(new Student(first, last, gpa)); // Add 2nd student
first = "Lynda";
last = "Robison";
gpa = 3.2;
course.addStudent(new Student(first, last, gpa)); // Add 3rd student
first = "Sonya";
last = "King";
gpa = 3.9;
course.addStudent(new Student(first, last, gpa)); // Add 4th student
Student student = course.findStudentHighestGpa();
System.out.println("Top student: " + student); //Expect: Sonya
}
}