public class MultidimensionalArraysExercises{

    /* Two-dimensional Arrays
      2. Write a method that takes a two-dimensional array as a parameter (and
      no other parameters). Have the method populate each value in the array.
      Start with 0.0 in the first index, then 0.001 in the second, etc.
      What should the return value be? Write some code to test your method.
    */
    /**
     * Simulates data with 0.000 in the first element and 0.001 in the second, etc.
     * @param arr A rectangular or ragged array
     */
    public static void populate( double[][] arr ){

        double value = 0.0;
        double step = 0.001; // the amount to increase value by for each index

        // For each row, iterate through each column
        for( int rowIndex = 0; rowIndex < arr.length; ++rowIndex){
            for( int colIndex = 0; colIndex < arr[rowIndex].length; ++colIndex){
                arr[rowIndex][colIndex] = value;
                value += step;
            }
        }

      }

    /* Two-dimensional Arrays
      3a. Write a method that takes a two-dimensional array as a parameter (and
      no other parameters). Have the method return the total of all of the
      values in the array. Write some code to test your method. (If you use the
      method described above to populate each value in the rainfall array, then
      you should get a total of approximately 66.43. Note, if you're getting a
      total of 69.006, then you're probably using a rectangular array instead of
      a ragged or jagged array.)
    */

    /**
     * Calculates the total of all of the values
     * @param arr A rectangular or ragged array
     * @return The sum of all of the values in array
     */
    public static double total( double[][] arr ){
        double total = 0.0;

        for( int rowIndex = 0; rowIndex < arr.length; ++rowIndex){
            for( int colIndex = 0; colIndex < arr[rowIndex].length; ++colIndex){
                total = total + arr[rowIndex][colIndex];
            }
        }

        return total;
    }

    public static void main( String[] args ){

        /* Two-dimensional Arrays
        1. Declare a two-dimensional array that can hold the amount of rainfall
        for everyday in a year. The first index should be the month and the
        second index the day of the month.
        */
        // 1D array:
        // dataType[] variableName = new dataType[size];
        // 2D array:
        // dataType[][] variableName = new dataType[size][size2];
        double[][] rainfallRectangular = new double[12][31]; // row, column
        // or
        double[][] rainfall = new double[12][]; // ragged array
        int monthIndex = 0;
        rainfall[ monthIndex++ ] = new double[31]; // January
        rainfall[ monthIndex++ ] = new double[29]; // February
        rainfall[ monthIndex++ ] = new double[31]; // March
        rainfall[ monthIndex++ ] = new double[30]; // April
        rainfall[ monthIndex++ ] = new double[31]; // May
        rainfall[ monthIndex++ ] = new double[30]; // June
        rainfall[ monthIndex++ ] = new double[31]; // July
        rainfall[ monthIndex++ ] = new double[31]; // August
        rainfall[ monthIndex++ ] = new double[30]; // September
        rainfall[ monthIndex++ ] = new double[31]; // October
        rainfall[ monthIndex++ ] = new double[30]; // November
        rainfall[ monthIndex++ ] = new double[31]; // December

        populate( rainfall );

        System.out.println( "Last rainfall amount: " + rainfall[ 11 ][ 30 ] );

        /* Two-dimensional Arrays
          3b. Write some code to test your method.
          (If you use the method described above to populate each value in the
          rainfall array, then you should get a total of approximately 66.43.
          Note, if you're getting a total of 69.006, then you're probably using
          a rectangular array instead of a ragged or jagged array.)
        */

        double total = total( rainfall );
        System.out.println( "Total rainfall: " + total );



        /* Multidimensional Arrays
          1. Declare a multi-dimensional array that can hold the amount of
          rainfall for everyday in a year for 100 years. The first index should
          be the year, the second index the month and the third index the day of
          the month. Will the methods described above work in this three-
          dimensional array? Discuss with someone else why or why not.
        */

        double[][][] centuryRainfall = new double[100][12][31];

    }
}