Discussion Section 8: Arrays of Objects

Due: 10pm Tuesday March 20

Purpose:  In this discussion section, you will manipulate arrays of objects and read from files using the Scanner class.



You will write two Java classes, a class Student and a class StudentGrades. The class Student will contain two instance variables: the variable name (String) and the variable grade (double) to record the name and the student's average grade. Your program will read Student records stored in a file, create Student objects out of the information that resides in the file, calculate the average grade of each student, and find the student with the greatest average.

The contents of the file that contains the student records must be of the form:

n m          <------- n = number of student records, m = number of grades per student   
Paul         <---|--- 1-st student record (with m = 3)
90 80 70     
<---|
John
85 92 75
....
Jack         <---|-- n-th student record
95 90 93     
<---|

We provide you with this sample.

As shown above, the first line will contain two integers: one specifying how many student records will follow inside the file and another integer specifying how many grades each student record will contain. The rest of the file will comprise of pairs of consecutive lines that record the name and grades of each student. 

The class StudentGrades must only contain the main method of your program. Inside your main method, you should read the information from the file, create an array of students (Student[]), create Student objects as specified by the imput file, and store the Student objects inside the array. Then, you will go over the elements of the array and find the Student with the largest average grade. Your program should print out the information for all students, along with a special message denoting the student that has the greatest average.

We have provided a sample input file (sample input file) and templates (StudentTemplate.java, StudentGradesTemplate.java) for each of the two classes with signatures of all the constructors and methods you should define. You can also add any helper methods you need for you implementation. 

Here is a template header to include in all your java files.

/**
* @author name 1: discussion section time:
* @CS account user name:  
*
* @author name 2: discussion section time:
* @CS account user name:
 *
* @version Date
*
*/
Your program should be internally correct (sound logic) and externally correct (following Java style guideline).