title: How to write this generic object program?
body: <p>Problem: Define a Rectangle class that provides getLength and getWidth methods. Using the
  findMax routines in Figure 1.18, write a main that creates an array of Rectangle
  and finds the largest Rectangle first on the basis of area, and then on the basis of perimeter.</p>
  
  <p>What I did so far was create a class rectangle with parameters width and height in the constructor. After that I implemented the two getter methods in which the instance variable width and height are return for their respective getter methods. So I need help with the second part. </p>
  
  <p>Figure 1.18</p>
  
  <pre><code>1 // Generic findMax, with a function object.
  2 // Precondition: a.size( ) &gt; 0.
  3 public static &lt;AnyType&gt;
  4 AnyType findMax( AnyType [ ] arr, Comparator&lt;? super AnyType&gt; cmp )
  5 {
  6 int maxIndex = 0;
  7
  8 for( int i = 1; i &lt; arr.size( ); i++ )
  9 if( cmp.compare( arr[ i ], arr[ maxIndex ] ) &gt; 0 )
  10 maxIndex = i;
  11
  12 return arr[ maxIndex ];
  13 }
  14
  15 class CaseInsensitiveCompare implements Comparator&lt;String&gt;
  16 {
  17 public int compare( String lhs, String rhs )
  18 { return lhs.compareToIgnoreCase( rhs ); }
  19 }
  20
  21 class TestProgram
  22 {
  23 public static void main( String [ ] args )
  24 {
  25 String [ ] arr = { "ZEBRA", "alligator", "crocodile" };
  26 System.out.println( findMax( arr, new CaseInsensitiveCompare( ) ) )
  27 }
  28 }
  </code></pre>