Problem Description The Kuala Lumpur International Airport (KLIA) is growing increasingly prominent as a hub for interna
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Problem Description The Kuala Lumpur International Airport (KLIA) is growing increasingly prominent as a hub for interna
The formula for distance measurements is derived from the Pythagorean theorem. Where the formula for distance between point p(xp, Yp) and q(xq, Yq) is d = √ ((xp-xq)²+ (Yp-Yq)²) de √(x,-x.) (x,-v₁) * (x1,y1) x2-x1 (x2,y2) y2-yl Used Math.sqrt(M) method to perform the distance calculation. The java.lang.Math.sqrt() returns the square root of M value of type double passed to it as an argument. Example: Double M = 81; System.out.println (Math.sqrt (M)); // prin- value 9.0 Input The first two integers represent the coordinate for point A, followed by nine coordinates for points P1 to P9. Output Display all nine distances in ascending order, followed by two coordinates representing the closest and farthest distances from point A.
Sample Input-Output Input 39 3579-3 104-12801160-911-223 Output 4.0 4.0 6.08 8.54 10.3 13.6 18.25 21.02 The closest point to A: (3,5) (7,9) The farthest point to A: (4,-12)
Solution Given the algorithm for the distance on a Cartesian plane: 1. Define a Cartesian Point class that has; • Three attributes: x-axis, y-axis and DistancefromA 2. Create a List of CartesianPoint. 3. Read the coordinate of point A 4. For each other points a. Read the given point b. Compute the distance between the given point from point A. c. Create an object of CartesianPoint d. Store the point and the distance in the CartesianPoint object. e. Add the Cartesian Point object to the list. Sort the list in ascending order. 6. 7. Display all distances from the list, including the closest and farthest distances from point A.