/**
 * Class that calculates the average of a collection of grades,
 * possibly dropping the lowest grade.
 *   @author Dave Reed
 *   @version 2/14/2010
 */
public class GradeCalculator1 {
    private int gradeTotal;
    private int numberOfGrades;
    private int lowestGrade;

    /**
     * Constructor for objects of class GradeCalculator.
     */
    public GradeCalculator1() {
        this.gradeTotal = 0;
        this.numberOfGrades = 0;
        this.lowestGrade = -1;
    }

    /**
     * Enters a grade and updates the totals accordingly.  
     *   @param nextGrade the grade to be entered (it is assumed that grades are in the range 0 to 100)
     */
    public void enterGrade(int nextGrade) {
        this.gradeTotal += nextGrade;
        this.numberOfGrades++;
        if (this.numberOfGrades == 0 || nextGrade < this.lowestGrade) {
            this.lowestGrade = nextGrade;
        }
    }
    
    /**
     * Accessor method for the number of grades.
     *   @return the number of grades entered so far
     */
    public int getNumberOfGrades() {
        return this.numberOfGrades;
    }

    /**
     * Accessor method for the lowest grade.
     *   @return the lowest grade entered so far (returns -1 if no grades entered)
     */
    public int getLowestGrade() {
        return this.lowestGrade;
    }
    
    /**
     * Determines the average of the grades entered so far.
     *   @return the average of the grades (if no grades entered, returns 0.0; 
     *   if at least 5 grades, then the lowest grade is dropped)
     */
    public double getAverage() {
        if (this.numberOfGrades == 0) {
            return 0.0;
        }
        else if (this.numberOfGrades < 5) {
            return (double)this.gradeTotal/this.numberOfGrades;
        }
        else {
            return (double)(this.gradeTotal-this.lowestGrade)/(this.numberOfGrades-1);
        }
    }
    
    /**
     * Determines the letter grade earned by the current grades entered.
     *   @return the letter grade ("A" for 90+, "B" for 80+, etc.)
     */
    public String getLetterGrade() {
        double avg = this.getAverage();
        if (avg >= 90) {
            return "A";
        }
        else if (avg >= 80) {
            return "B";
        }
        else if (avg >= 70) {
            return "C";
        }
        else if (avg >= 60) {
            return "D";
        }
        else {
            return "F";
        }
    }
}
