Gr H.

asked • 01/20/22

what is the answer to the question in the description

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 getPerimeter() returns the perimeter of a rectangle. What will print when index = 3?

 a Area = 9 Perimeter = 12
 b Area = 4 Perimeter = 8
 c Area = 16 Perimeter = 16
 d Area = 25 Perimeter = 20
 e Area = 1 Perimeter = 4


Dan B.

c. As index 3 refers to the 4th element, it will be referencing the Rectangle(4,4) so the area will be 4x4 and the perimeter will be 4+4+4+4 (which is the same thing
Report

01/20/22

1 Expert Answer

By:

Luke L. answered • 04/27/22

Tutor
5 (17)

Senior FAANG Software Engineer Specializing in Java

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.