我必须编写遍历的findStudentWithMaxGPA()方法 带有for循环的数组,并返回带有max的学生的名字 GPA。 但是,我不知道如何使用for循环来执行此操作。
public class P4CRoster
{
private String name;
private P4C[] students;
public P4CRoster( )
{
students = new P4C[3];
students[0] = new P4C("Hieu Tran", 4.0, 4.0, 4.0, 4.0, 4.0);
students[1] = new P4C("Steven Nguyen", 3.5, 3.5, 3.5, 3.5, 3.5);
students[2] = new P4C("Saul Sanchez", 3.0, 3.0, 3.0, 3.0, 3.0);
}//end method
public double findStudentWithMaxGPA()
{
double x = students[0].calcGPA();
double y = students[1].calcGPA();
double z = students[2].calcGPA();
x.compareTo(y);
x.compareTo(z);
y.compareTo(z);
}//end method
public String toString()
{
String output = new String();
output = "The Student with the max GPA is: " + findStudentWithMaxGPA;
return output;
}//end toString
}