Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

D Model.java 3 1 package code; 3 import java . util,HashMap;0 Homework 3, part 2

ID: 3601591 • Letter: D

Question

D Model.java 3 1 package code; 3 import java . util,HashMap;0 Homework 3, part 2 10 This homework is the second step to a geography-based application and will 11 give you practice with the following concepts: 12 13 14 15 16 17 In this homework you will work with a real-world data set that contains 18 approximately 48,080 city names, locations, and populations from around 19 the world. The data is in the WorldCitiesPop.csv file in the Data folder. 28 21 Each line of this file has the following structure: 22Country, City, AccentCity,Region, Population, Latitude, Longitude 23 24 THE City CLASS 25 26 You will need to keep all the data for a City together in one place. To do 27 this you define a City class that has an instance variable for the following 28 fields: 29 30 31 32 33Population store this as an int 34 35 36 7 Notice that AccentCity is missing you may safely ignore this field 38 39 The City class must have a constructor that accepts these values as Strings reading data from a file structuring data Filtering data Country store this as a String City store this as a String Region store this as a String Latitude - store this as a double Longitude store this as a double Country, City, Region, Population, Latitude, Longitude 1 *and initializes the above instance variables as expected 43 * Define also a simple ecessor. method for each of the instance variables 45 THE CityPair CLASS 7 Sometimes you need to work with pairs of cities rather than just individual 48*cities. The CityPair class has a constructor that takes two City objects and 49 stores each in its own instance variable

Explanation / Answer

Hi,

I have created three classes City.java, CityPair.java and Model.java as below. I have also created Testing.java to test the methods of Model class. Please use Console output for testing purposes. You did not provide the.csv data file, so I have created a sample file WorldCitiesPop.csv temporarily for input, Whose contents are as below:

US,Idaho Falls,Northwest,56813,43.49307183,-112.0362926
US,Ammon,Northwest,13816,43.4696366,-111.9666355
US,Iona,Northwest,1803,43.5263026,-111.9330238
US,Island Park,Northwest,286,44.4243637,-111.3710645
US,Sugar City,Northwest,1514,43.8729673,-111.7482976
US,Ririe,Northwest,656,43.6318576,-111.773575

I have ignored AccentCIty as it is not useful for calculations, but if you want you can add it in the file. For ther you have to make little adjustment in the code. Please find all jaava files below:

City.java

CityPair.java

Model.java

I have added only those methods which are not defined and which are required. You can add remaining methods which are already there and test them below in Testing.java

Testing.java

NOTE: There is no change in Point2D.java. You have to add it as it is.

Let me know if you have any further questions.