Lab 10

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

PROBLEM PROMPTS

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:

1. Airport.java   Download Airport.java: a class to represent an


airport

2. AirportsReader.java   Download AirportsReader.java: a class that


reads in a file of airports and puts them into a List<Airport>.

3. Coordinates.java   Download Coordinates.java: a class that


represents a set of latitude/longitude coordinates and provides a
method for calculating the distance between two sets of
coordinates

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:

1. AirportsStats.java  Download AirportsStats.java

problem1_countAirports

Given a Stream of airports, return the number of airports in the Stream.

Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem1_countAirports(airportsList.stream()); // returns 237

problem2_countCountries

Given a Stream of airports, return the number of different countries


represented in the Stream.

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

Given a Stream of airports, a set of coordinates, and an int numMiles, return a


String that contains the names of all airports within numMiles, from those
coordinates, ordered lexicographically, each name separated by ", ". Use
the Coordinates.distance method to calculate distance (but remember to convert
between miles and meters. 

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

Given a Stream of airports, return a Given a Map<Double, Long> that maps


altitudes to the number of airports at that altitude, but only include in the map
altitudes that have at least 2 airports at that altitude. If the stream is empty,
return an empty map.

return a list of movies with exactly n words in the title (use String.split("\\s+") to


split the title string into words).

Example:
List<Airport> airportsList6 = AirportsReader.readAirports("airports6.dat");
problem8_countAirportsByAltitude(airportsList6.stream());
// the above returns map: {0.0=6, 4150.0=4}

problem9_averageNumAirportsPerCountry

Given a Stream of airports, return the average number of airports in each


country, of 0 if the stream is empty.

Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem9_averageNumAirportsPerCountry(airportsList.stream()); // returns
31.827004

 
problem10_percentAirportsWithCityName

Given a Stream of airports, return the percentage of airport names that


contain the name of the city they are in (case-insensitive). If a city name is
blank, consider the airport name to NOT contain it. If the stream is empty,
return 0.

Example:
List<Airport> airportsList = AirportsReader.readAirports("airports.dat");
problem10_percentAirportsWithCityName(airportsList.stream()); // returns
62.309425957841704

You might also like