/* * File: GymnasticsMean.java * -------------------------- * This file reads in an array of scores and computes the * average. * * Author: CS1MD3, Nov. 2008 */ import acm.program.*; public class GymnasticsMean extends ConsoleProgram { public void run() { double[] scores = new double[N_JUDGES]; for (int i = 1; i <= N_JUDGES; i++) { scores[i - 1] = readDouble("Enter score for judge " + i + ": "); } println("The average score is " + mean(scores)); } /** * Calculates the mean of a double array * @param array An array of doubles * @return The mean of the array */ public double mean(double[] array) { int n = array.length; double total = 0; for (int i = 0; i < n; i++) { total += array[i]; } return total / n; } /* Private constant */ private static final int N_JUDGES = 5; /* number of judges */ }