Question: Write a method called centroid that takes one formal parameter of type OUPolygon and returns the centroid of the actual parameter as a Point, which

Write a method called centroid that takes one formal parameter of type OUPolygon and returns the centroid of the actual parameter as a Point, which is another class in the java.awt library.
Use a for-each loop (see p.116 of Barnes and Kolling) to access each of the 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. (It is preferable to keep decimal places and round to an integer at the end.)
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!