Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Best Route(IN JAVA) Write a program named BestRoute that reads in the coordinates of four points on a two-dimensional surface (a plane). Each point has

Best Route(IN JAVA)

Write a program named BestRoute that reads in the coordinates of four points on a two-dimensional surface (a plane). Each point has an x-coordinate and a y-coordinate. Each point has a one-token label (which is read in, as part of the input), for example:

A 5.0 5.0 Q 10.0 10.0 R 7.0 7.0 Z 6.0 6.0

The program computes the total distance involved in traveling from the first point (in this example 5.0,5.0) to the last point (6.0,6.0) via the second point (10.0,10.0 in this example) and the total distance via the third point (7.0,7.0 in this case). In other words, it computes the path length of A-Q-Z and the path length of A-R-Z. It then displays the shorter path by printing the labels of the points in the shorter path:

Best Route: A-R-Z

(The other possibility would have been "A Q Z" but the program should have determined that A-Q-Z was longer than A-R-Z.)

The BestRoute program should use and contain definitions of the following methods, which you've written previously: getPathLength, distance2p, sqr.

(IN JAVA)

sqr code and distance 2p code public static double distance2p(double x1, double y1, double x2, double y2){ return Math.sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))); } public static double sqr(double a){ return a*a; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions