2005 Average

<< 2005Tickets | APQuestionsTrailIndex | 2004 WordList >>

Question from the College Board


public class StudentRecord
{
        private int[] scores;

        private double average(int first, int last)
        {
               //part a

         }

        private boolean hasImproved()
        {
             //part b

        }
        public double finalAverage()
        {
            //part c  

         }

 }



Driver to test it out:

public class AverageTester{

    public static void main (String[] args)
    {
     //I made 3 integer arrays in  three different ways!
     int[] a1={50, 50, 20, 80, 53};
     StudentRecord s1=new StudentRecord(a1);

     int a2[]={20, 50, 50, 53, 80};
     StudentRecord s2=new StudentRecord(a2);
     int[] a3=new int[4];
     a3[0]=20;
     a3[1]=a3[2]=50;
     a3[3]=80;
     StudentRecord s3=new StudentRecord(a3);

     System.out.println("s1 improved? (should be false):"+ s1.hasImproved());
     System.out.println("s2 improved? (should be true):"+ s2.hasImproved());
     System.out.println("s3 improved? (should be true):"+ s3.hasImproved());

     System.out.println("s1 average? (should be 50.6):"+ s1.finalAverage());
     System.out.println("s2 average? (should be 61.6):"+ s2.finalAverage());
     System.out.println("s3 average? (should be 65.0):"+ s3.finalAverage());
    }

}