Question: Stuck on this (JAVA) Shortest path utility program: Using the methods sqr distance2p and getPathLength to write a program named ShortestPath that compares two paths.
Stuck on this (JAVA)
Shortest path utility program: Using the methods sqr distance2p and getPathLength to write a program named ShortestPath that compares two paths. (You wrote those methods in previous labs.) Here are the details: The program reads two lines of input like the following:
lake_route 1.4 2.9 4.3 8.7 9.0 10.0 meadow_route 1.1 4.7 5.3 8.9 10.0 9.0
Each line consists of a string identifying (labeling) the path followed by three pairs of doubles. Each pair of doubles represents a point (x,y). Each line's sequence of three pairs represents a path of three points. The program uses getPathLength (which in turn uses the other two methods distance2p and sqr) to compute the total distance of each of the paths. The program then prints out 3 lines:
the path name and length of the first path
the path name and length of the second path
the path name of the shortest path
TWO OTHER METHODS :
public static double sqr(double x) { return Math.pow(x, 2.0); } public static double distance2p(double x1, double y1, double x2, double y2) { return Math.sqrt(sqr(x2-x1)+sqr(y2-y1)); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
