/** 
 *  Program that reads in the average monthly rainfall for a city for each 
 *  month of the year and then reads in the actual monthly rainfall for each 
 *  of the previous 12 months. Program then outputs a formatted table to show
 *  deviations from the average. Program uses an object called RainfallData to
 *  store the average rainfall, the actual rainfall and the deviation (whether
 *  it be positive or negative). The program contains a method display() which
 *  outputs a table of the data.
 */

package rainfalldata;

import java.util.Scanner;

/**
 *
 * @author k8port
 */
public class RainfallData {
    
    enum Months {JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, 
                    SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER};
    
    // class variables
    Months[] months; // an array to hold the enum type
    String city; // name of city
    private double[] averages;  // array to hold average rainfall per month
    private double[] actuals;   // array to hold actual rainfall per month
    private double[] deviation; // array to hold amonth of deviation from actual to average
    
    /**
     * Constructs an RainfallData object which holds average and actual rainfall
     * as well as deviations. Uses user input to gather data.
     */
    public RainfallData() {
        Scanner kbd = new Scanner(System.in);
        months = Months.values();
        System.out.println("Enter city name: ");
        city = kbd.nextLine();
        fillAverage(kbd);
        fillActual(kbd);
        fillDeviation();
    }
    
    /**
     * Method to fill averages[] with average monthly average rainfall amounts.
     * @param scanner the object used to gather data from console
     * @param month the array to hold the month values
     */
    private void fillAverage(Scanner scanner) {
        averages = new double[months.length];
        for (int i = 1; i <= months.length; i++) {
            System.out.println("Enter " + city + " average rainfall for " 
                    + months[i-1] + ":");
            averages[i-1] = scanner.nextDouble();
        }
        System.out.println("");
    }
    
    /**
     * Method to fill actuals[] with actual monthly rainfall amounts.
     * @param scanner the I/O console object
     * @param month the array to hold month values
     */
    private void fillActual(Scanner scanner) {
        actuals = new double[months.length];
        System.out.println("Enter the current month number:");
        int response = scanner.nextInt();
        System.out.println("");
        for (int i = response-1; i > 0; i--) {
            System.out.println("Enter " + city + " actual rainfall for " 
                    + months[i-1] + ":");
            actuals[i-1] = scanner.nextDouble();
        }
        for (int j = months.length; j >= response; j--) {
            System.out.println("Enter " + city + " actual rainfall for " 
                    + months[j-1] + ":");
            actuals[j-1] = scanner.nextDouble();
        }
        System.out.println("");
    }
    
    /**
     * Method to fill deviation[] with difference between average and actual
     * monthly rainfall. Negative amounts indicate actual rainfall was less 
     * than average. Positive amounts indicate actual rainfall was greater 
     * than average.
     * @param month the array to hold month values
     */
    private void fillDeviation(){
        deviation = new double[months.length];
        for (int i = 0; i < months.length; i++) {
            deviation[i] = actuals[i] - averages[i];
        }
    }
    
    /**
     * Method that outputs a table showing rainfall data. 
     */
    public void display() {
        String one = "Average";
        String two = "Actual";
        String three = " | ";
        System.out.println(city.toUpperCase());
        for (int i = 0; i < months.length; i++) 
            System.out.printf("%-13s%1s",months[i].toString(), three);
        System.out.print("\n");
        for (int j = 0; j < months.length; j++) 
            System.out.printf("%5s %5s%1s", one, two, three);
        System.out.println("\n");
        for (int k = 0; k < months.length; k++) 
            System.out.printf("%5.2f   %5.2f%1s", averages[k], actuals[k], three);
        System.out.println("\n");
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        RainfallData yourCity = new RainfallData();
        yourCity.display();
    }
    
}





@@ -3760,11 +3760,17 @@
  = %22
- %7C 
+Deviation
 %22;%0A 
@@ -3860,24 +3860,25 @@
 ength; i++) 
+%7B
 %0A           
@@ -3903,18 +3903,17 @@
 (%22%25-13s%25
-1s
+n
 %22,months
@@ -3930,99 +3930,11 @@
 ng()
-, three
 );%0A
-        System.out.print(%22%5Cn%22);%0A        for (int j = 0; j %3C months.length; j++) %0A
     
@@ -3967,19 +3967,22 @@
 %22%255s %255s
-%251s
+ %255s%25n
 %22, one, 
@@ -3998,91 +3998,8 @@
 e);%0A
-        System.out.println(%22%5Cn%22);%0A        for (int k = 0; k %3C months.length; k++) %0A
     
@@ -4042,11 +4042,17 @@
 5.2f
-%251s
+    %255.2f
 %22, a
@@ -4063,20 +4063,41 @@
 ges%5B
-k
+i
 %5D, 
+%0A                    
 actuals%5B
 k%5D, 
@@ -4096,17 +4096,24 @@
 als%5B
-k%5D, three
+i%5D, deviation%5Bi%5D
 );%0A 
@@ -4111,32 +4111,36 @@
 on%5Bi%5D);%0A        
+    
 System.out.print
@@ -4147,14 +4147,22 @@
 ln(%22
-%5Cn
 %22);%0A
+        %7D%0A
     

Update RainfallData.java