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.
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(); } }
//student.java
import java.text.*; /************************************************* * A simple student class including name and gpa. * *************************************************/ public class Student{ /** student name */ private String first, last; /** student GPA */ private double gpa;
/************************************************ Constructor for Student ************************************************/ public Student(String f, String l, double d){ first = f; last = l; gpa = d; } /************************************************ @return GPA ************************************************/ public double getGPA(){ return gpa; }
/************************************************ @return last name ************************************************/ public String getLast(){ return last; } /************************************************ to String @return String representation of the object ************************************************/ public String toString(){ DecimalFormat fmt = new DecimalFormat("#.0"); return first + " " + last + " " + fmt.format(gpa); } public static void main (String [] args){ Student s = new Student ("Henry", "Walker", 3.6); System.out.println(s); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
