Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am stuck on a problem that requires me to come up with a way to calculate the largest side perimeters of different shapes. I am kind of confused on how to even start with it tbh.



This is some of the code.

public class PerimeterAssignmentRunner {

public double getPerimeter (Shape s) {

double totalPerim = 0.0;

Point prevPt = s.getLastPoint();

for (Point currPt : s.getPoints()) {

double currDist = prevPt.distance(currPt);

totalPerim = totalPerim + currDist;

prevPt = currPt;

}

// totalPerim is the answer

return totalPerim;

}





The package was provided with points given in another file (don't know the exact the terminology).

What I have tried:

double largestSide = 0;
Point prevPt = s.getLastPoint();
for(Point currPt:s.getPoints())
Posted
Updated 11-Nov-18 20:00pm

1 solution

Work out the length of each segment, that is basic Pythagoras: BBC - GCSE Bitesize: The length of a line segment[^]
Then all you have to do is work out the longest...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900