Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Work exercise 13.12, page 530, to write a method to sum the areas of all geometr

ID: 3586307 • Letter: W

Question

Work exercise 13.12, page 530, to write a method to sum the areas of all geometric objects stored in an array. Follow the textbook specification for the new method and write a test program as specified in the problem statement

*13.12 (Sum the areas of geometric objects) Write a method that sums the areas of all the geometric objects in an array. The method signature is:
public static double sumArea(GeometricObject[] a)
Redesign the Rectangle class VideoNote
Write a test program that creates an array of four objects (two circles and two rectangles) and computes their total area using the sumArea method.

Explanation / Answer

public static double sumArea(GeometricObject[] a)

{

double sum = 0.0;

int itr;

for(itr=0; itr<a.length; itr++)

{

if( a[0] instanceof Circle)

sum = sum + (3.14*a[i].radius*a[i].radius);

elseif ( a[0] instanceof Rectangle)

sum = sum + a[i].length*a[i].breadth;

}

return sum;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote