Question: Given a file with multiple records , each containing 2 pairs of numbers: an x-axis coordinate and a y-axis coordinate. There is no order to

Given a file with multiple recordsGiven a file with multiple records, each containing 2 pairs of numbers:, each containing 2 pairs of numbers: an x-axis coordinate and a y-axis coordinate. There is no order to the records in the file. Here is a skeleton of a starter file. Write a program that will find the pairs of coordinates that are closest to each other, as if these were 2 planes in space, flying too close to each other. Report of the 2 pairs of coordinates that are closest to each other. Display a warning message such as:

"Alert, Alert! Plane at coordinate: x-axis, y-axis is too close to Plane at coordinate: x-axis, y-axis."

Hints:

1.) Define a class that can hold 2 coordinates. Call it the Location class. Implement the Comparable interface, and thus create a compareTo() method.

2.) Create an array of Location objects, from reading the input file. (Note: the first record in the input file contains the number of records in the file).

3.) Sort the array by either x- or y-coordinate (use either the insertion sort or the selection sort algorithm. Do NOT use Collections.sort()...)

4.) Compare each object in the sorted array with the previous object, and calculate their distance by using the Pythagorean formula below:

double distanceBetween2Points = Math.sqrt((x2 - x1)^2 + (y2 - y1)^2)

Note: to get the square of a number in Java, use Math.pow(base, exponent)

5.) Good luck! Their safety depends on you!

Note: To process the input file that contains spaces and commas separating each word in each record, please use the following method to specify MULTIPLE delimeters:

inFile.useDelimiter(", |\ \ ");

file: airplaneInMiami.txt

18 5, 2 8, 10 12, 6 2, 9 1, 10 3, 4 13, 5 16, 7 9, 14 6, 5 4, 1 2, 3 4, 5 10, 4 19, 3 1, 7 5, 5 6, 8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!