I'm supposed to complete computeStudentMean method and the displayMeans method. Method computeStudentMean accesses the four grades in each individual student record, computes the mean of the four grades and stores the result in mean. Method displayMeans list all the student name and their respective test averages.
My problem is that I keep on getting an error that says I have a ClassCastException
Code:
import java.io.*; 
import java.util.ArrayList; 
    
  
  
public class lab20 
{ 
   public static void main(String args[]) throws IOException 
   { 
      System.out.println("Lab 20 80/100 POINT VERSION"); 
      ClassList list = new ClassList(); 
      list.getList(); 
      list.pause(); 
      list.computeStudentMean(); 
//      list.computeTestMean(); 
//      list.computeClassMean(); 
      list.displayMeans();       
      System.out.println(); 
   } 
} 
  
  
class ClassList 
{    
  
   class Student 
   { 
      private String name; 
      private ArrayList grades; 
      private double mean; 
    
      public Student(String n, int g1, int g2, int g3, int g4) 
      { 
         name = n; 
         grades = new ArrayList(); 
         grades.add(new Integer(g1)); 
         grades.add(new Integer(g2)); 
         grades.add(new Integer(g3)); 
         grades.add(new Integer(g4)); 
      } 
   } 
  
   private ArrayList students; 
   private int studentCount;    
   private ArrayList testMean; 
   private int testCount; 
    private double classMean; 
    
   public ClassList() 
   { 
      students = new ArrayList();  
      testMean = new ArrayList(); 
      studentCount = 0; 
      testCount = 4;          
   } 
  
   public void getList() throws IOException 
   { 
      System.out.println("\nRetrieving Grades.dat\n"); 
      FileReader inFile = new FileReader("Grades.dat");    
      BufferedReader inStream = new BufferedReader(inFile);         
      String s1,s2,s3,s4,s5; 
      while(    ((s1 = inStream.readLine()) != null) && 
            ((s2 = inStream.readLine()) != null) && 
            ((s3 = inStream.readLine()) != null) && 
            ((s4 = inStream.readLine()) != null) && 
            ((s5 = inStream.readLine()) != null)   ) 
      { 
         System.out.println(s1 + "\t\t" + s2 + "\t" + s3 + "\t" + s4 + "\t" + s5); 
         String name = s1; 
         int g1 = Integer.parseInt(s2); 
         int g2 = Integer.parseInt(s3); 
         int g3 = Integer.parseInt(s4); 
         int g4 = Integer.parseInt(s5); 
         students.add(new Student(name,g1,g2,g3,g4));        
      }    
      inStream.close();                   
      studentCount = students.size(); 
   } 
   public void pause() throws IOException 
   {    
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));    
      String dummy; 
      System.out.print("\nPress <Enter> to continue  ===>>  ");                   
      dummy = input.readLine();                         
   } 
    
    
   public void displayData() 
   { 
      System.out.println("\nDISPLAYING STUDENT DATA"); 
   }    
    
   public void computeStudentMean() 
   { 
      int sum=0; 
      for(int k=0; k<studentCount; k++) 
      { 
      Integer temp = (Integer) students.get(k); <--ERROR OCCURS HERE 
      sum += temp.intValue(); 
  
      } 
   double mean =(double)sum/4; 
   testMean.add(new Double(mean));    
   } 
    
    
   public void computeTestMean() 
   {    
   } 
    
    
   public void computeClassMean() 
   {    
   } 
  
  
     public void displayMeans() 
   { 
   System.out.println("\nDISPLAYING MEAN STATISTICS"); 
      for(int k=0; k><testMean.size(); k++) 
            System.out.println((Double) testMean.get(k)); 
   }    
  
}
Am I getting this error because my code is completely wrong, or is it that I accessed a wrong record, and if so, how can I correct it? Thank you.