Question
Perform queries of Trash Site data from the Environmental Protection Agency (EPA). The data we will use is located at https://www.epa.gov/frs/epa-state-combined-csv-download-files. It is recommended that
Perform queries of Trash Site data from the Environmental Protection Agency (EPA). The data we will use is located at https://www.epa.gov/frs/epa-state-combined-csv-download-files.
It is recommended that you develop a sequential program that solves the problem, to debug your serial code, before you tackle the concurrent solution, to make it easier to debug the parallel version.
The NATIONAL_FACILITY_FILE.CSV is useful for our assignment. For your convenience, it is broken down into files of 10,000 lines or fewer in a zip file.
You should prompt the user for a latitude, longitude and directory (folder) location, as follows: Enter your latitude: 44.9575346 Enter your longitude: -93.0761363 Enter the absolute pathname of your data directory: C:MetroStateEPAData
You may store your data wherever you wish, but you must include the pathname that contains all of the files, so that I can enter a different pathname on my computer and access my own copies of the files. Please do not make any modifications to the string that is entered as the pathname within your program. The coordinates above are of the Metro State Labyrinth.
Each line in each file contains data for a TrashSite, including the address, latitude and longitude, site type, etc. The file is in CSV format. To help you parse the data, you may read in the files line-by-line. The Java String class contains a method, split, that will split the data into separate fields as follows:
String[] parts = line.split(",");
The lines contain data fields that are documented in the package downloaded from the EPA. However, you may simply use the following fields of the files.
Field 0 is the URL for the site. To obtain the URL, remove the quotation marks from the field: String URL = parts[0].replaceAll("^"|"$", "");
Field 1 is the name of the site. To obtain the name, remove the quotation marks from the field: String name = parts[1].replaceAll("^"|"$", "");
Field 2 is the address of the site. To obtain the address, remove the quotation marks from the field: String address = parts[2].replaceAll("^"|"$", "");
Field 27 is the latitude of the site, in positive or negative degrees. To obtain the latitude, remove the quotation marks from the field and convert it to a double: double latitude = Double.parseDouble(parts[27].replaceAll("^"|"$", ""));
Field 28 is the longitude of the site, in positive or negative degrees. To obtain the longitude, remove the quotation marks from the field and convert it to a double: double longitude = Double.parseDouble(parts[28].replaceAll("^"|"$", ""));
Note that some of the listing do not contain latitude and longitude pairs. In this case, parseDouble() will throw a NumberFormatException and you may ignore that line.
You may obtain the distance in miles between two coordinate pairs using the following method:
public static double distance(double lat1, double long1, double lat2, double long2) { lat1 = Math.toRadians(lat1); long1 = Math.toRadians(long1); lat2 = Math.toRadians(lat2); long2 = Math.toRadians(long2); return 6371 * 2 * Math.asin(Math.sqrt( Math.pow(Math.sin((lat2 - lat1) / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin((long2 - long1) / 2), 2))); }
The extracted files compose approximately 2 Gigabytes, so ensure are using a system that can handle this amount of data.
Your program should print the eight sites nearest to the entered latitude and longitude.
You should use Thread Pools, Futures and Callables to complete processing. Your program should create a thread pool with 8 threads. Then, your program should create one future for each file, and submit that future for execution. Upon completion, each Callable should return up to eight results for each file, since it is likely that one file contains several of the nearest results.
As you retrieve the results from each Future, you should add those results to one of four "results" lists of type TrashSite. The first Future's eight results should be appended to the first list; the second future's eight results to the second list, the third to the third list, the fourth to the fourth list, and the fifth to the first list. You should continue in this manner until all the results have been collected.
Then, you should create a second set of four Callables. You may use the same thread pool. Each set of should collect the closest 8 results for each site. You should collect the results from each future into a single list.
Then, in a single thread, you should find the top 8 results from the single list. You should then print the final 8 results in the following format:
URL=https://ofmpub.epa.gov/frs_public2/fii_query_detail.disp_program_facility?p_registry_id=110011399218 name=110011399218 address=WATHENA USD 406 latitude=39.76376 longitude=-94.95263 distance=597.6994199451829
Please do not use GUI elements for any portion of your program.
Objectives:
- Follow the assignment directions. - Create a program that prints the minimum or maximum elements corresponding to the criteria entered. - Use thread pools, futures, and callables, correctly, and as specified in the assignment. - Use no locks. - Read the files concurrently. - Sift the top answers out of the input concurrently. - Print the output station and station information correctly. - Do not submit the provided data to D2L.
Program Submission
Develop and submit the program using the Program Submission Instructions in the Course Materials section of the Course Content.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres the Java program that utilizes thread pools futures and callables to find the nearest trash sites Java import javaioBufferedReader import javaioFileReader import javaioIOException import javauti...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started