import java.util.*; /** * Class that represents a student * @author Barb Ericson */ public class Student { //////////// fields /////////////////// private String firstName; private String lastName; private String pictureFileName; private List gradeList = new ArrayList(); ////////////// constructors ////////////// /** * No argument constructor. All fields * are their default values */ public Student() {} /** * Constructor that takes the firstName, lastName, * and picture file name * @param firstName the first name to use * @param lastName the last name to use * @param pictureFile the name of the picture file */ public Student(String firstName, String lastName, String pictureFile) { this.firstName = firstName; this.lastName = lastName; this.pictureFileName = pictureFile; } //////////////// methods ////////////////// /** * Method to get the first name * @return the student's first name */ public String getFirstName() { return firstName; } /** * Method to set the first name * @param firstName the first name to use */ public void setFirstName(String firstName) { this.firstName = firstName; } /** * Method to get the last name * @return the last name */ public String getLastName() { return lastName; } /** * Method to set the last name * @param lastName the last name to use */ public void setLastName(String lastName) { this.lastName = lastName; } /** * Method to get the picture file name * @return the picture file name */ public String getPictureFileName() { return pictureFileName;} /** * Method to set the picture file name * @param pictureFile the picture file to use */ public void setPictureFileName(String pictureFile) { pictureFileName = pictureFile; } /** * Method to add a grade * @param grade the grade to add to the list * of grades */ public void addGrade(double grade) { gradeList.add(new Double(grade)); } /** * Method to calculate a grade point average * from the list of grades * @return the average of the grades */ public double getGradeAverage() { double total = 0; double grade = 0; Double tempDouble = null; // iterator through the list Iterator iterator = gradeList.iterator(); while (iterator.hasNext()) { tempDouble = (Double) iterator.next(); grade = tempDouble.doubleValue(); total = total + grade; } return total / gradeList.size(); } /** * Main method for testing */ public static void main(String[] args) { Student me = new Student("Barb","Ericson",null); me.addGrade(80.5); me.addGrade(93.5); me.addGrade(73.8); System.out.println(me.getGradeAverage()); } }