11. Given the following class

import java.util.ArrayList;
public class RectangleTester
{

public static void main(String[ ] args)

{

ArrayList< Rectangle > shapes = new ArrayList< Rectangle >();

shapes.add(new Rectangle(1, 1));

shapes.add(new Rectangle(2, 2));

shapes.add(new Rectangle(3, 3));

shapes.add(new Rectangle(4, 4));


Rectangle dataRecord;


for(int index = 0; index < shapes.size(); index++)

{

dataRecord = shapes.get(index);

dataRecord.calcRectArea();

dataRecord.calcRectPerimeter();

System.out.println(Area = + dataRecord.getArea());

System.out.println(Perimeter = + dataRecord.getPerimeter());

}

}

}

Assume that getArea() returns the area of a rectangle and getRectPerimeter() returns the perimeter of a rectangle. What will print when index = 3? (3 points)

Question 11 options:

1) Area = 9
Perimeter = 12

2) Area = 4
Perimeter = 8

3) Area = 16
Perimeter = 16

4) Area = 25
Perimeter = 20

5) Area = 1
Perimeter = 4

Respuesta :

There are 4 rectangles in the ArrayList shapes. ArrayLists start counting at 0 so when index is 3, dataRecord will be the 4th rectangle. The length and width of the 4th rectangle in shapes are both 4 so the area is 16 and the perimeter is 16. The answer is 3.






Answer:

I would have given the same answer but the guy above already has