Beginning Arrays (growth)
CS 161 - Spring 2009

Due: no later than the start of lab on April 15th or 16th to your new professor's grader account ___________________

Goal
to declare and use arrays to remember information that must be handled more than once

Overview
For this activity, you will write a program that will read a series of real values representing the yearly growth of pine trees, average the values, and then print the values and their difference from the average. You must use an array of doubles to hold the values.

Input Specification
The input will contain a series of real (double) values. Your program should handle up to 10 values. It will print error messages if there are no values. Any input beyond 10 values should be ignored. (It would be better to alert the user that you are ignoring values, but the goal of this assignment is to use arrays.) Your program should read until end-of-file (type control-d if typing on the keyboard) or 10 values have been read. You should not prompt for input or echo the values as you read them. It is a good idea to define a constant, i.e. a public static final int, for the maximum number of values (10).

Output Specification
The first output is a count of how many values are included in the calculations. The second output is the average. Then, for each value, you will print the tree's index in the array, its growth value, and that value's difference from the average. Print each real value with one digit after the decimal point. An output line looks like:
   Tree 3 grew 12.4 which is -2.3 from the average
To print with one digit after the decimal point, use this constant declaration:
   public static final DecimalFormat fmt = new DecimalFormat("0.0");
Then you can convert a number, x, to the appropriate format with  fmt.format(x) 
Eclipse will prompt you to import java.text.DecimalFormat

If there are no values, you should print an error message. Do not divide by zero, do not print any data, and do not compute or print the average. Just print an error message and stop.

If the user inputs more than the allowed number of values, ignore those extra values. You may print an alert message, but you should average and report on the first allowed number of values.

Approaching the Problem
Develop your solution incrementally. This problem naturally uses functions extensively. Remember that each function should have a short comment describing what it does. Writing that comment before writing the code helps you think about what you are writing and why. We suggest the following iterations.

Sample Input
6.5 7.8 -1.4 9 22 -2.73 0 17

Sample Output
8 values included in calculations
The average is 7.3
Tree 0 grew 6.5 which is -0.8 from the average
Tree 1 grew 7.8 which is 0.5 from the average
Tree 2 grew -1.4 which is -8.7 from the average
Tree 3 grew 9.0 which is 1.7 from the average
Tree 4 grew 22.0 which is 14.7 from the average
Tree 5 grew -2.7 which is -10.0 from the average
Tree 6 grew 0.0 which is -7.3 from the average
Tree 7 grew 17.0 which is 9.7 from the average