Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Largest city: 18.73 million located at 45.79 lat, -138.2 lon... Smallest city: 2.3 million located at -71.18 lat, -62.53 lon... Total: 116.84 million in


image

Largest city: 18.73 million located at 45.79 lat, -138.2 lon... Smallest city: 2.3 million located at -71.18 lat, -62.53 lon... Total: 116.84 million in 12 cities... Exercise 2 [20%] This exercise requires you to design classes, read data from a file into a data structure and create a command line based user interface. To avoid naming conflicts place all of the classes in a package, e.g. ex2. The goal of this exercise is read data from a file containing names, locations and sizes of 4000 cities from around the world. This data was obtained from https://simplemaps.com/data/world-cities that was released under the Creative Commons Attribution 4.0. Exercise 2A [12%] Read the data from the file worldcities.csv (available from Moodle) into a data structure of your choice. For this purpose, design a class called CityData (you may create additional classes) that provides the following methods: printLargest10: returns void, has no parameters and prints the largest 10 cities in the following format (you will need to read ASCII name, latitude, longitude, country and population from the file; note only two cities are shown to conserve space): Tokyo located at 35.6897 latitude 139.6922 longitude in Japan with a population of 37977000 Jakarta located at -6.2146 latitude 106.8451 longitude in Indonesia with a population of 34540000 printSmallest10: returns void, has no parameters and prints the smallest 10 cities (see example in 2B) printCountry: returns void, receives a String containing a country name as parameter and prints all cities from that country (see example in 2B) printClosest 10: returns void, receives two double as parameter that contain latitude and longitude, and prints the 10 cities closest to the coordinates (see example in 2B); you may assume the Earth is a perfect sphere and compute the distance with the Haversine formula Exercise 2B [8%] Create a class called MainCity with a main () method. The class should read the data from the file using the code you wrote for 2A and ask for input via the following command line interface: Please enter: 1 to print 10 largest cities 2 to print 10 smallest cities 3 to enter a country and print cities from this country 4 to enter a latitude and longitude and print 10 closest cities. quit to quit Entry of a 1 by the user should print the ten largest cities (one per line) from the file using print Largest 10 () in the following format (it is not a solution to hard code this output, it needs to be read from the file): Tokyo located at 35.6897 latitude 139.6922 longitude in Japan with a population of 37977000 Jakarta located at -6.2146 latitude 106.8451 longitude in Indonesia with a population of 34540000 Note the example above only shows the first two cities. Correspondingly entry of a 2 should print the 10 smallest cities in the same format using printSmallest10 (). Entry of a 3 should prompt the user to enter the name of a country, e.g.: Please enter: 1 to print 10 largest cities 2 to print 10 smallest cities. 3 to enter a country and print cities from this country 4 to enter a latitude and longitude and print 10 closest cities quit to quit Enter country name: United Kingdom London located at 51.5072 latitude -0.1275 longitude in United Kingdom with a population of 10979000 Birmingham located at 52.48 latitude -1.9025 longitude in United Kingdom with a population of 2897303 Note the example above only shows the first two cities. Entering a non-existent country name should return to the main menu: 3 Enter country name: sdfsdf Please enter: 1 to print 10 largest cities. 2 to print 10 smallest cities 4 3 to enter a country and print cities from this country. 4 to enter a latitude and longitude and print 10 closest cities quit to quit Entry of a 4 should prompt the user for a latitude and longitude and call printClosest 10 (), e.g.: 4 Enter latitude and longitude: 42 42 Batumi located at 41.6458 latitude 41.6417 longitude in Georgia with a population of 154600 Kutaisi located at 42.25 latitude 42.7 longitude in Georgia with a population of 147900 Note the example above only shows the first two cities. Generally, the menu should return to the main menu after output is printed. There should be no inputs that cause the program to terminate except quit. Please enter: 1 to print 10 largest cities 2 to print 10 smallest cities. 3 to enter a country and print cities from this country 4 to enter a latitude and longitude and print 10 closest cities quit to quit quit Bye!

Step by Step Solution

3.36 Rating (149 Votes )

There are 3 Steps involved in it

Step: 1

2A Creating Classes package ex2 public class MainEx2 public static void mainString args TreeData treeData new TreeDatatreesPrunedcsv treeDataprintTreesPerBorough treeDataprintMostCommonAge public clas... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions