Professional Documents
Culture Documents
Lab 10
Lab 10
Lab 10
This lab is all about airports. Using a large dataset of airports around the world,
you will use Java Streams to analyze all sorts of interesting characteristics of
the dataset.
You are given three files to use as-is for this lab. Do not modify these files:
You are given one template file to fill in with all of the required
methods. Modify this file by filling in the method bodies, but DO NOT
CHANGE ANY METHOD SIGNATURES:
problem1_countAirports
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem1_countAirports(airportsList.stream()); // returns 237
problem2_countCountries
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem2_countCountries(airportsList.stream()); // returns 7543
problem3_getAirportAtLowestAltitude
Given a Stream of airports, return the airport at the lowest altitude (use
the min method of the Stream class)
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem3_getAirportAtLowestAltitude(airportsList.stream()); // returns Airport
#1600
problem4_getAirportsInCity
Given a Stream of airports and the name of a city, return a list of airports in
that city, sorted in ascending lexicographic order by airport name
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem4_getAirportsInCity(airportsList.stream(), "Chicago");
// the above returns a list with airports #8593, 3747, 3830, 3818
problem5_getAllAirportsWithinNumMiles
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem5_getAllAirportsWithinNumMiles(airportsList.stream(), new
Coordinates(33.6405, -117.8443, 10));
// the above returns: "El Toro Marine Corps Air Station, John Wayne Airport-Orange
County Airport"
problem6_getTopNcountriesWithMostAirports
Given a Stream of airports and an int n, return a list of the names of the
top n countries with the most airports, sorted in descending order by number
of airports. If there are < an n countries represented in the stream, return them
all, sorted in descending order by number of airports.
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem6_getTopNcountriesWithMostAirports(airportsList.stream(), 3);
// returns a list containing "United States", "Canada", "Australia"
problem7_getClosestAirport
Given a Stream of airports and an airport ID, return the airport closest to the
airport with that ID. Use the Coordinates.distance method to calculate distance
between airports, and the Stream.min method to find the airport with the
minimum distance away. If the airport with the given ID is not found, or the
stream is empty, return an empty Optional<Airport>.
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem7_getClosestAirport(airportsList.stream(), 3830); // returns airport #7936
problem8_countAirportsByAltitude
Example:
List<Airport> airportsList6 = AirportsReader.readAirports("airports6.dat");
problem8_countAirportsByAltitude(airportsList6.stream());
// the above returns map: {0.0=6, 4150.0=4}
problem9_averageNumAirportsPerCountry
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem9_averageNumAirportsPerCountry(airportsList.stream()); // returns
31.827004
problem10_percentAirportsWithCityName
Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem10_percentAirportsWithCityName(airportsList.stream()); // returns
62.309425957841704