// play with arrays of objects
// experiment with Intervals

public class array_objects {
  public static void main(String args[]) {
      //------------------------------------
      // create array of interval references:
      // -> Is contains two references to 
      //    Interval objects
      //------------------------------------
      Interval[] Is = new Interval[2];

      //------------------------------------
      // so far, Is is an array of refs!
      // instantiate each element of Is
      // -> each element will be a reference
      //    to a created Interval object
      //------------------------------------
      Is[0] = new Interval("A",1,2);
      Is[1] = new Interval("B",3,4);
      
      //------------------------------------
      // do something with Is
      // how about printing each interval?
      //------------------------------------
      for(int i=0; i<=1; i++) 
	  Is[i].print();
      
      /* NOTE: The for-loop could be expressed as:
       *       Is[1].print();
       *       Is[2].print();
       *
       *       Is[i].print()
       *       ^^^^^
       *       this part means, "the ith element of 
       *       array Is" which is an Interval object
       *
       *       To access an object's field, use the
       *       the syntax <array>[<index>].<field>
       *
       *       Don't like the syntax? Sorry.
       *       The following expressions won't work:
       *       BAD: Is.print()[i]
       *       BAD: (Is.print())[i]
       */
      
  } // method main

} // class array_objects


//---------------------------------------------------------
// INTERVAL CLASS
//---------------------------------------------------------
class Interval {
    double min;
    double max;
    String name;
    Interval(String n, double x, double y) {
	name = n;
	min = x;
	max = y;
    } // constructor
    public void print() {
	System.out.println(name+": ["+min+","+max+"]");
    } // method print
} // class Interval

//---------------------------------------------------------
/* Output:
A: [1.0,2.0]
B: [3.0,4.0]
*/

