title: Java Arrays and Referencing
body: <p>As part of the curriculum at my school, we are working on some CodeHS Java.
  There is one problem that I'm stuck on:</p>
  <blockquote>
  <p>Taking our Student and Classroom example from earlier, you should fill in the method getMostImprovedStudent, as well as the method getExamRange. The most improved student is the one with the largest exam score range.</p>
  <p>To compute the exam score range, you must subtract the minimum exam score from the maximum exam score.</p>
  <p>For example, if the exam scores were 90, 75, and 84, the range would be 90 - 75 = 15.</p>
  </blockquote>
  <p>This is the Student class which I added my method <code>getExamRange()</code>.</p>
  <pre><code>import java.util.*;
  
  public class Student
  {
      private static final int NUM_EXAMS = 4;
      
      private String firstName;
      private String lastName;
      private int gradeLevel;
      private double gpa;
      
      private int[] exams;
      private int numExamsTaken;
      public static int[] examRange = new int[Classroom.numStudentsAdded];
      private int i = 0;
  
      /**
       * This is a constructor.  A constructor is a method
       * that creates an object -- it creates an instance
       * of the class. What that means is it takes the input
       * parameters and sets the instance variables (or fields)
       * to the proper values.
       * 
       * Check out StudentTester.java for an example of how to use
       * this constructor. 
       */
      public Student(String fName, String lName, int grade)
      {
          firstName = fName;
          lastName = lName;
          gradeLevel = grade;
          exams = new int[NUM_EXAMS];
          numExamsTaken = 0;
      }
      
      public int getExamRange()
      {
          Arrays.sort(exams);
          examRange[i] = exams[exams.length-1] - exams[0];
          i++;
          return exams[exams.length-1] - exams[0];
      }
      
      public String getName()
      {
          return firstName + &quot; &quot; + lastName;
      }
      
      public void addExamScore(int score)
      {
          exams[numExamsTaken] = score;
          numExamsTaken++;
      }
      
      // This is a setter method to set the GPA for the Student.
      public void setGPA(double theGPA)
      {
          gpa = theGPA;
      }
      
      /**
       * This is a toString for the Student class. It returns a String
       * representation of the object, which includes the fields
       * in that object.
       */
      public String toString()
      {
          return firstName + &quot; &quot; + lastName + &quot; is in grade: &quot; + gradeLevel;
      }
  }
  </code></pre>
  <p>And this is the Classroom class in which I added the method <code>getMostImprovedStudent()</code>.</p>
  <pre><code>import java.util.*;
  
  public class Classroom
  {
      Student[] students;
      static int numStudentsAdded;
      
      public Classroom(int numStudents)
      {
          students = new Student[numStudents];
          numStudentsAdded = 0;
      }
      
      public Student getMostImprovedStudent()
      {
          Arrays.sort(Student.examRange);
          //return Student.examRange[0];
      }
      
      public void addStudent(Student s)
      {
          students[numStudentsAdded] = s;
          numStudentsAdded++;
      }
      
      public void printStudents()
      {
          for(int i = 0; i &lt; numStudentsAdded; i++)
          {
              System.out.println(students[i]);
          }
      }
  }
  </code></pre>
  <p>I can get the exam Range by sorting the exams array then subtracting the smallest from the biggest, but once I do this, how do I find the student with the biggest exam range, and return it?</p>