Question: StudentLinkedList, given below, is a linked list where the data is an instance of the inner class Student. Student data is name and GPA. The

StudentLinkedList, given below, is a linked list where the data is an instance of the inner class Student. Student data is name and GPA. The list is not sorted. Write a method getStudentWithHighestGPA that returns the name of the student with the highest GPA. If the list is empty return an empty String.

There is test code in main. You only need to submit the new method.

public class StudentLinkedList { private Node head = null; public class Node { Student data; Node next; Node(Student s) { data = s; } } public class Student { private String name; private double GPA; public Student(String n, double g) { name = n; GPA = g; } } public void insert(Student s) { Node newNode = new Node(s); newNode.next = head; head = newNode; } public static void main(String[] args) { StudentLinkedList list = new StudentLinkedList(); list.insert(list.new Student("student1", 3.6)); list.insert(list.new Student("student2", 3.1)); list.insert(list.new Student("student3", 2.5)); list.insert(list.new Student("student4", 3.9)); list.insert(list.new Student("student5", 2.9)); System.out.println(list.getStudentWithHighestGPA()); } }

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!