6 Replies Latest reply: Apr 8, 2008 10:27 PM by 807591 RSS

    Simple problem involving Arrays

    807591
      I was doing fine until, we had to switch everything from arrays to arraylists. It keeps giving me this one error and I have idea why...
      package spreadsheet;
      
      import java.util.*;
      public class SpreadSheet
      {
          // instance variables - replace the example below with your own
          private ArrayList<StudentScores> course = new ArrayList<StudentScores>();
          private int scores;
          //private int[][] grades;
          //private int[] maxScore;
           //private int[] weight = {14,14,20,35,15,2};
          private int numStudents;
          private double score;
          Scanner in = new Scanner(System.in);
          private int sum;
          private int avg;
          
      
          /**
           * Constructor for objects of class SpreadSheet
           */
          public SpreadSheet(int students)
          {
              numStudents = students;
              ArrayList<StudentScores> course = new ArrayList<StudentScores>();
              //maxScore = new int[6];
              //getScores();
              
          }
      
          //public void displayFinals()
          //{
          //    for (int i = 0; i < numStudents; i ++)
          //    {
          //        double finalScore = 0;
          //        for (int j = 0; j < 6; j++)
          //        {
          //            finalScore += (double) grades[i][j]/maxScore[j] * weight[j];
          //        }
          //        System.out.format("Student %d final score: %5.1f%n", i,  finalScore );
          //    }
          //}
          //public void displayStats()
          //{
          //    int sum = 0;
          //    double mean = 0;
          //    int col = 0;
          //    for (int i = 0; i < 6; i++)
          //    {
          //        for (int j = 0; j < numStudents; j++)
          //        {
          //            sum +=  grades[j];
      // }
      // mean = (double) sum/numStudents;
      // System.out.format("Mean for column %d is: %5.1f%n", col, mean);
      // col++;
      // mean = 0;
      // sum = 0;
      // }
      //}
      public void displayStats()
      {
      int index;
      for (index = 0; index < 6; index++)
      sum = 0;
      for (StudentScores student : course)
      sum += course.getScore(index);// < This part here gives me cannot find getScore, but when I try to move getScore it gets angry because the Arraylist is in //the other class...
      avg = sum / numStudents;
      }
      public void removeStudent(String name)
      {
      for (StudentScores student : course)
      if (student.getName().equals(name))
      course.remove(student);
      }
      }
      And the other part.
      package spreadsheet;

      import java.util.*;

      public class StudentScores
      {  
      private int sum;
      private int index;
      private int numStudents;
      private String studentName;
      private int[] scores;
      private int[] maxScore;
      Scanner in = new Scanner(System.in);

      public void StudentScores(String name)
      {
      ArrayList<StudentScores> course = new ArrayList<StudentScores>();
      System.out.println("Please enter the student name");
      studentName = name;
      numStudents++;
      for ( int i = 0; i < 6; i++ )
      {
      System.out.println("Please enter six scores for student " + i);
      for (int j = 0; j < 6; j++)
      scores[i] = in.nextInt();
      }
      System.out.println("Enter the maximum scores for each component");
      for (int i = 0; i < 6; i++)
      {
      maxScore[i] = in.nextInt();
      }
      }
      public int getScore(int index)
      {
      return scores[index];
      }

      public String getName()
      {
      return studentName;
      }

      }
      Any pointer would be nice...