Question: Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called findHighestStudent() as described below. Refer
Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called findHighestStudent() as described below. Refer to Student.java below to learn what methods are available.
Code:
import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{
/** collection of Students */ private ArrayList
/***************************************************** Constructor for objects of class Course *****************************************************/ public Course(){ roster = new ArrayList
/***************************************************** @return Student with highest GPA *****************************************************/ public Student findHighestStudent(){ /** Your code goes here */ } /***************************************************** Add a student to the course *****************************************************/ public void addStudent(Student s){ roster.add(s); } /***************************************************** Main method for testing *****************************************************/ public static void main(String args[]){ Course cis162 = new Course(); cis162.addStudent(new Student("Henry", "Cabot", 3.2)); cis162.addStudent(new Student("Brenda", "Stern", 4.0)); cis162.addStudent(new Student("Lynda", "Robison", 3.2)); cis162.addStudent(new Student("Jane", "Flynn", 3.9)); Student stud = cis162.findHighestStudent(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
