
import java.util.Scanner;

public class AirPollutionReport {

	public static void main(String[] args) {
		final int NUM_READINGS = 5;
		double [] readings = new double[NUM_READINGS];
		readReadingsInto(readings);
		System.out.printf( "\nThe average is %.3f%n", average(readings) );
		print(readings);
	}

	private static void readReadingsInto(double[] anArray) {
		Scanner kbd = new Scanner(System.in);
		System.out.println("To compute the air pollution index...");
		for (int i = 0; i < anArray.length; i++) {
			System.out.print("Enter reading #" + 
					            (i+1) + "/" + 
					            anArray.length + ": " );
			anArray[i] = kbd.nextDouble();
		}
	}
	
	public static double average(double [] anArray) {
		if (anArray.length < 1) {
			throw new IllegalArgumentException("average(): array is empty");
		}
		double sum = 0.0;
//		for (int i = 0; i < anArray.length; i++) {
//			sum += anArray[i];
//		}
		for (double it : anArray) {
			sum += it;
		}
		return sum/anArray.length;
	}
	
	public static void print(double [] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.println("Reading #" + (i+1) + ": " +  arr[i]);
		}
	}
}
