import java.util.ArrayList;
import java.util.Scanner;

/**
   This program computes a final score for a series of quiz scores: the sum after dropping 
   the lowest score.
*/
public class Scores
{
   public static void main(String[] args)
   {
      ArrayList<Double> scores = readInputs();
      if (scores.size() == 0)
      {
         System.out.println("At least one score is required.");
      }
      else
      {
         double total = sum(scores) - minimum(scores);
         System.out.println("Final score: " + total);
      }
   }

   /**
      Reads a sequence of floating-point numbers.
      @return an ArrayList containing the numbers
   */
   public static ArrayList<Double> readInputs()
   {
      ArrayList<Double> inputs = new ArrayList<Double>();
      System.out.println("Please enter values, Q to quit:");
      Scanner in = new Scanner(System.in);
      while (in.hasNextDouble())
      {  
         inputs.add(in.nextDouble());
      }
      return inputs;
   }
   
   /**
      Computes the sum of the values in an array list
      @param data an array list
      @return the sum of the values in data
   */
   public static double sum(ArrayList<Double> data)
   {
      double total = 0;
      for (double element : data)
      {
         total = total + element;
      }
      return total;
   }
      
   /**
      Gets the minimum value from an ArrayList.
      @param data an ArrayList of size >= 1
      @return the smallest element of data
   */
   public static double minimum(ArrayList<Double> data)
   {
      double smallest = data.get(0);
      for (int i = 1; i < data.size(); i++)
      {
         if (data.get(i) < smallest)
         {
            smallest = data.get(i);
         }
      }
      return smallest;
   }
}

