import java.util.ArrayList;

/**
 * Class that stores grades and can calculate overall GPA.
 *   @author Dave Reed
 *   @version 11/1/17
 */
public class GradeBook {
  private ArrayList<Grade> grades;
  
  /**
   * Constructs an empty grade book.
   */
  public GradeBook() {
      this.grades = new ArrayList<Grade>();
  }
  
  /**
   * Adds a letter grade to the list of grades.
   *   @param g the letter grade (e.g., "A", "B+")
   *   @param h the number of course hours
   */
  public void addGrade(String g, int h) {
    this.grades.add(new LetterGrade(g, h));
  }
  
  /**
   * Adds a pass/fail grade to the list of grades.
   *   @param g whether the student passed
   *   @param h the number of course hours
   */
  public void addGrade(boolean g, int h) {
    this.grades.add(new PassFailGrade(g, h));    
  }
  
  /**
   * Calculates the overall GPA.
   *   @return the GPA (between 0.0 and 4.0)
   */
  public double GPA() {
     double pointSum = 0.0;
     int hourSum = 0;
     for (Grade nextGrade : this.grades) {
        pointSum += nextGrade.gradePoints();    
        hourSum += nextGrade.hours();
     }
     return pointSum/hourSum;
  }
}
