/**
 * Sums all the command line arguments as ints and then
 * prints the total and average.
 * 
 * @author Zach Tomaszewski
 */
public class Adder {

  public static void main(String[] args) {

    if (args.length == 0) {
      //print error/usage message
      System.out.println("Error: No command line arguments given.");
      System.out.println();
      System.out.println("Adder sums the command line arguments given.");
      System.out.println("Example usage: java Adder 2 2");

    }else {
      try {
        //sum all args as ints
        int sum = 0;
        for (String arg : args) {
          sum += Integer.parseInt(arg);
        }

        //print results
        System.out.println("Sum: " + sum);
        System.out.println("Average: " + (double) sum / args.length);
      }catch (NumberFormatException nfe) {
        System.out.println("Sorry, but you must enter only integers.");
      }
    }
  }
}
