Question: package code; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import code.Point2D; /* * Homework 3, part 2 * * This homework is

package code;

import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap;

import code.Point2D;

/* * Homework 3, part 2 * * This homework is the second step to a geography-based application and will * give you practice with the following concepts: * * reading data from a file * structuring data * filtering data * * In this homework you will work with a real-world data set that contains * approximately 48,000 city names, locations, and populations from around * the world. The data is in the WorldCitiesPop.csv file in the Data folder. * * Each line of this file has the following structure: * Country,City,AccentCity,Region,Population,Latitude,Longitude * * THE City CLASS * ============== * You will need to keep all the data for a City together in one place. To do * this you define a City class that has an instance variable for the following * fields: * * Country - store this as a String * City - store this as a String * Region - store this as a String * Population - store this as an int * Latitude - store this as a double * Longitude - store this as a double * * Notice that AccentCity is missing - you may safely ignore this field. * * The City class must have a constructor that accepts these values as Strings, * Country, City, Region, Population, Latitude, Longitude * and initializes the above instance variables as expected. * * Define also a simple accessor method for each of the instance variables. * * THE CityPair CLASS * ================== * Sometimes you need to work with pairs of cities rather than just individual * cities. The CityPair class has a constructor that takes two City objects and * stores each in its own instance variable. * * The CityPair class also must have accessors for the two cities in the pair: * * public City cityOne() * public City cityTwo() * * * THE MODEL CLASS * =============== * Define, in the class Model the following methods: * * ArrayList readDataFromCSV(String filename) * This method reads the data from the indicated filename and returns a few ArrayList containing the data * read in from the file. * * ArrayList filterByCountry(String country, ArrayList cities) * This method builds and returns a new ArrayList containing those City objects that are in the indicated country. * If there are no cities in the requested country the ArrayList returned is empty. * * ArrayList filterByRegion(String region, ArrayList cities) * This method builds and returns a new ArrayList containing those City objects that are in the indicated region * If there are no cities in the requested region the ArrayList returned is empty. * * ArrayList filterByMinimumPopulation(int minimumPopulation, ArrayList cities) * This method builds and returns a new ArrayList containing those City objects that have a population greater * than or equal to minimumPopulation. If there are no cities in the with the requested population the ArrayList * returned is empty. * * ArrayList filterByMaximumPopulation(int maximumPopulation, ArrayList cities) * This method builds and returns a new ArrayList containing those City objects that have a population less * than or equal to maximumPopulation. If there are no cities in the with the requested population the ArrayList * returned is empty. * * CityPair furthestApart(ArrayList cities) * This method returns a CityPair containing the two City objects that are furthest apart in the cities ArrayList. * * CityPair clostestTogether(ArrayList cities) * This method returns a CityPair containing the two City objects that are closest together in the cities ArrayList. * * int totalPopulation(ArrayList cities) * This method returns the combined population of all the City objects in the cities ArrayList. *

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!