title: Accessing properties of objects in an ArrayList
body: <p>I need to build a method to find the sum of the areas of the rectangles in a given <code>ArrayList</code> of rectangles.</p>
  
  <pre><code>public class Homework {
  public static void main(String[] args) {
      ArrayList&lt;Rectangle&gt; test = new ArrayList&lt;Rectangle&gt;();
      test.add(new Rectangle(10, 20, 30, 40));
      test.add(new Rectangle(10, 10, 30, 40));
      test.add(new Rectangle(20, 20, 40, 50));
      test.add(new Rectangle(20, 10, 50, 30));
      System.out.println(areaSum(test));
      System.out.println("Expected: 5900.0");
      System.out.println(areaAverage(test));
      System.out.println("Expected: 1475.0");
  }
  
  public static double areaSum(ArrayList&lt;Rectangle&gt; rects){
      //work goes here
  }
  </code></pre>
  
  <p>What I have so far is:</p>
  
  <pre><code>public static double areaSum(ArrayList&lt;Rectangle&gt; rects){
      double totalArea = 0;
      for (Rectangle r : rects) {
          double area = (x + width) * (y + height);
          totalArea = totalArea + area;
      }
      return totalArea;
  }
  </code></pre>
  
  <p>How can I pull the dimensions of the rectangles from the <code>ArrayList</code> built by the tester block? I'm sort of new to the field, this is a homework assignment and I can't seem to figure it out.</p>