Question: Write a method called centroid that takes one formal parameter of type Polygon and returns the centroid of the actual parameter as a Point. Use

Write a method called centroid that takes one formal parameter of type Polygon and returns the centroid of the actual parameter as a Point.
Use a for-each loop polygons points.
Accumulate the total of the x values and the total of the y values of the polygons points.
Once you have the totals, divide each by the number of points to find their means.
Return a Point object whose x and y coordinates are integer approximations of the mean x and y values in the polygon poly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!