/*
  still playing with arrays
  - now trying to break the rules!
  - pay attention to all the common mistakes below
  */

public class array2 {

  public static void main(String args[]) {

    // declare array
    int[] a = new int[7];

    // do mot say:
    //     int[a] = new int[]
    //     int[] = new int[a]
    //     int[] = a[]
    
    // store values the long way
    a[0] = 7;
    a[1] = -1;
    a[2] = 2;
    a[3] = 3;
    a[4] = 0;
    a[5] = 1;
    a[6] = 4;

    // do not say:
    //     a[-1] = value
    //     a[7] (array starts at 0 and ends at 6!)
    //     an assignment backwards, like 7 = a[0]


    /******************/
    /* OTHER PROBLEMS *
    /******************/
    
    //==================================================//
    // FAILURE #1					//
    //==================================================//
    // Try to reassign a
    // Once assigned, an array cannot be reassigned
    // The following code won't compile!
    /****************************/
    // double[] a = new double[];
    /****************************/

    //==================================================//
    // FAILURE #2					//
    //==================================================//
    // Try to change a's size
    // This fails too because Java thinks you're
    // still trying to reassign a!
    /****************************/
    // int[] a = new int[10];
    /****************************/


    //==================================================//
    // FAILURE #3					//
    //==================================================//
    // Try to reassign still using an initializer lisr
    // This fails too because Java thinks you're
    // still trying to reassign a!
    /****************************/
    // int[] a = {0, 1, 2, 3, 4, 5, 6};
    /****************************/
    // Give it up! You cannot reassign an array

    //==================================================//
    // FAILURE #4					//
    //==================================================//
    // Try to store a value beyond
    // an array's limits/dimension
    /****************************/
    // a[8] = 14;
    /****************************/
    // this code will compile but won't run:
    // Java told me "java.lang.ArrayIndexOutOfBoundsException: 8
    //                      at array2.main(Compiled Code)"

    //==================================================//
    // FAILURE #5					//
    //==================================================//
    // Try to access element that's outside of bounds
    /****************************/
    // System.out.println(a[10]);
    /****************************/
    // this code will compile but won't run:
    // Java told me "java.lang.ArrayIndexOutOfBoundsException: 10
    //                      at array2.main(Compiled Code)"

    //===================================================//
    // FAILURE #6					 //
    //===================================================//
    // Try to access what you think is the last element of a
    // don't forget, you assign 7 elements to a:
    /****************************/
    // System.out.println(a[7]);
    /****************************/
    // this code will compile but won't run:
    // Java told me "java.lang.ArrayIndexOutOfBoundsException: 7
    //                      at array2.main(Compiled Code)"
    // Bzzzzz! Java starts the index from zero!!!
    // So, the last element is a[6], and NOT a[7]
    
  } // method main

} // class array2
