title: Running Method on Arrays in Java
body: <p>Got the classic assignment where I need to create Student and Course classes and a Driver class. </p>
  
  <p>I'm having trouble calculating the overall class average in my Course class. Everything works, but when I run the Driver, I get '0' back as the class average. In the IDE, it's telling me the 's' in my 's.getAverage();' in the getClassAverage method cannot be resolved, but I'm not really sure why as I am using that in other places just fine. I'm trying to run through an array of students and add all of their averages together. </p>
  
  <p>Any pointers? I appreciate your time!</p>
  
  <p>Student.java</p>
  
  <pre><code>public class Student
  {
  private String firstName, lastName;
  private int testScore1, testScore2, testScore3;
  private int studentAverage;
  
  //Constructors
  public Student()
  {
      firstName = "None";
      lastName = "None";
      testScore1 = 0;
      testScore2 = 0;
      testScore3 = 0;
      studentAverage = 0;
  }
  
  public Student(String first, String last, int score1, int score2, int score3)
  {
      firstName = first;
      lastName = last;
      testScore1 = score1;
      testScore2 = score2;
      testScore3 = score3;
  }
  
  //Setter for test scores
  public void setTestScore(int testNum, int score)
  {
      if (testNum == 1)
          testScore1 = score;
      else
          if (testNum == 2)
              testScore2 = score;
          else
            if (testNum == 3)
              testScore3 = score;
            else
              throw new IllegalArgumentException(testNum + " is out of range");
      }
  //Getter for test scores
  public int getTestScore(int testNum2)
  {
      if (testNum2 == 1)
          return testScore1;
      else
          if (testNum2 == 2)
              return testScore2;
          else
            if (testNum2 == 3)
              return testScore3;
            else
              throw new IllegalArgumentException(testNum2 + " is out of range");
      }
  
  //Getter for student first name and last name
  public String getFirstName()
  {
      return firstName;
  }
  
  public String getLastName()
  {
      return lastName;
  }
  
  //Calculates average for each student
  public int getAverage()
  {
      int studentAverage = (testScore1 + testScore2 + testScore3)/3;
      return studentAverage;
  }
  //Returns a description of this Student object
  public String toString()
  {
      String result;
  
      result = firstName + " " + lastName + "\n";
      result += "Test Score 1:\n" + testScore1 + "\n";
      result += "Test Score 2:\n" + testScore2 + "\n";
      result += "Test Score 3:\n" + testScore3 + "\n";
      result += "Average Test Score:\n" + studentAverage;
  
      return result;
  }
  }
  </code></pre>
  
  <p>Course.java</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Course {
  //What Course class knows
  private String courseName;
  private int classAverage;
  private int studentAverage, sumAverages;
  private ArrayList&lt;Student&gt; students;
  
  public static int count = 0;
  
  //Constructor
  public Course(String courseName)
  {
      this.courseName = courseName;
  
      students = new ArrayList&lt;Student&gt;();
  }
  
  //Add students
  public void addStudent(Student s)
  {
      students.add(s);
      ++count;
  }
  
  //Return average of all student test score averages
  public int getClassAverage()
  {
      for(Student s : students);
      {
          sumAverages += s.getAverage();
      }
  
      int classAverage = (int) sumAverages/students.size();
      return classAverage;
  }
  
  
  //Roll call - prints all students in the course
  public void roll()
  {
      System.out.println("Course: " + courseName);
      System.out.println("Number of Students: " + count);
      System.out.println("Students: ");
  
      for(Student s : students) 
      {
          System.out.println(s.getFirstName() + " " + s.getLastName());
      }
  }
  
  //Prints class average
  public String toString()
  {
      String result;
      result = "The class average is: "+ classAverage;
      return result;
  }
  
  }
  </code></pre>
  
  <p>Driver</p>
  
  <pre><code>public class CourseDriver {
  
  public static void main(String[] args) {
      //Create a new course
      Course course1 = new Course("CSC 140");
  
      //Create and add several students to course
      course1.addStudent( new Student("Sarah", "Mauer", 93, 82, 67) );
      course1.addStudent( new Student("Andrew", "Kagan", 85, 80, 75) );
      course1.addStudent( new Student("Carly", "Sanseverino", 95, 83, 80) );
  
      //Prints roll
      course1.roll();
  
      System.out.println(course1);
  }
  
  }
  </code></pre>