1  import java.util.ArrayList;
  2  
  3  public class GradeBook
  4  {
  5     private double[] scores;
  6     private int scoresSize;
  7  
  8     /**
  9        Constructs a gradebook with no scores and a given capacity.
 10        @capacity the maximum number of scores in this gradebook
 11     */
 12     public GradeBook(int capacity)
 13     {
 14        scores = new double[capacity];
 15        scoresSize = 0;
 16     }
 17  
 18     /**
 19        Adds a score to this gradebook.
 20        @param score the score to add
 21        @return true if the score was added, false if the gradebook is full
 22     */
 23     public boolean addScore(double score)
 24     {
 25        if (scoresSize < scores.length)
 26        {
 27           scores[scoresSize] = score;
 28           scoresSize++;
 29           return true;
 30        }
 31        else
 32           return false;      
 33     }
 34  
 35     /**
 36        Computes the sum of the scores in this gradebook.
 37        @return the sum of the scores
 38     */
 39     public double sum()
 40     {
 41        double total = 0;
 42        for (int i = 0; i < scoresSize; i++)
 43        {
 44           total = total + scores[i];
 45        }
 46        return total;
 47     }
 48        
 49     /**
 50        Gets the minimum score in this gradebook.
 51        @return the minimum score, or 0 if there are no scores.
 52     */
 53     public double minimum()
 54     {
 55        if (scoresSize == 0) return 0;
 56        double smallest = scores[0];
 57        for (int i = 1; i < scoresSize; i++)
 58        {
 59           if (scores[i] < smallest)
 60           {
 61              smallest = scores[i];
 62           }
 63        }
 64        return smallest;
 65     }
 66  
 67     /**
 68        Gets the final score for this gradebook.
 69        @return the sum of the scores, with the lowest score dropped if 
 70        there are at least two scores, or 0 if there are no scores.
 71     */
 72     public double finalScore() 
 73     {
 74        if (scoresSize == 0)
 75           return 0;
 76        else if (scoresSize == 1)
 77           return scores[0];
 78        else
 79           return sum() - minimum();
 80     }
 81  }
 82