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

(IN JAVA) Path: In this homework, you are to write a method (not a program!) and

ID: 3724228 • Letter: #

Question

(IN JAVA) Path: In this homework, you are to write a method (not a program!) and call it getPathLength. It receives 6 (omigod 6!) arguments: the x-coordinate and the y-coordinate of the first point in the path (2 values) the x-coordinate and the y-coordinate of the second point in the path (2 values) the x-coordinate and the y-coordinate of the third point in the path (2 values) The method returns the length of a path that starts at the first point and goes to the second point and then goes on to the third point. The method computes the length of the path by figuring out the distance between the first and second points and then the distance between the second and third points. The method you write must make use of the method distance2p. (You implemented that method in an earlier Lab.)

Explanation / Answer

Note- you haven't given the code of distance2p method, so i couldn't use it

public double getPathLength(int x1,int y1,int x2,int y2,int x3,int y3){

// Formula to find distance between 2 points

// d = sqrt((x2-x1)^2 + (y2-y1)^2)

// Find distance between first (x1,y1) and second point (x2,y2)

double distancep1p2=Math.sqrt(Math.pow((x2-x1), 2)+Math.pow((y2-y1), 2));

// Find distance between second (x2,y2) and third point (x3,y3)

double distancep2p3=Math.sqrt(Math.pow((x3-x2), 2)+Math.pow((y3-y2), 2));

// Add both distances calculated above

double totalDistance=distancep1p2+distancep2p3;

// Return total distance

return totalDistance;

}