Largest city: 18.73 million located at 45.79 lat, -138.2 lon... Smallest city: 2.3 million located at...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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! 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!
Expert Answer:
Answer rating: 100% (QA)
2A Creating Classes package ex2 public class MainEx2 public static void mainString args TreeData treeData new TreeDatatreesPrunedcsv treeDataprintTreesPerBorough treeDataprintMostCommonAge public clas... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
On February 1, 2020, Sheridan Company sells merchandise on account to Carla Vista Company for $6490. The entry to record this transaction by Sheridan Company is Sales Revenue Accounts Payable Notes...
-
Do companies outsource for ethical or sustainable reasons? If so, provide some examples.
-
Cond Nast Traveler publishes a Gold List of the top hotels all over the world. The Broadmoor Hotel in Colorado Springs contains 700 rooms and is on the 2004 Gold List (Cond Nast Traveler, January...
-
As an electron in a one-dimensional box of length \(0.600 \mathrm{~nm}\) jumps between two energy levels, a photon of energy \(8.36 \mathrm{eV}\) is emitted. What are the quantum numbers of the two...
-
The payroll records of Linda Vista Machining Co. show the following information for the week ended April 17: Hourly workers are paid time-and-a-half for overtime. a. Determine the net earnings of...
-
In what ways does the primary key establish a cardinal relationship between entities within a database, ensuring data consistency and coherence across related tables?
-
You are looking for an item in an ordered list 450,000 items long (the length of Webster's Third New International Dictionary). How many steps might it take to find the item with a sequential search?...
-
Identify three major groups of people involved in the research process, and then give an example of an unethical behavior sometimes practiced by each group.
-
The core is made of cast steel which has relative permeability of 4000. For a current of 8 A, calculate the number of turns required to produce a flux density of 2.2 T in the left leg of the core....
-
Say today is September 15th and that the bond last paid a coupon on April 30th of this year, the next coupon is on April 30th of next year, and the currently quoted price is 100. What is the Full...
-
Peter is making quarterly contributions of of $300 to his savings account which pays interest at the APR of 8.2%, compounded quarterly. Right after Peter makes his 40th contribution, the bank changes...
-
A manufacturing company pays $16,900 per month for rent and utilities, $47,250 for administrative salaries, $4,300 for insurance costs, and $61,433 for equipment rental. The variable costs are $37...
-
76. Given this figure with equal sides: a What is the sum of the angles a, b, c, d, and e? . 180 b. 175 140 d. 210 .
-
An investor sells a European call on a share for $4. The stock price is $47 and the strike price is $50. Under what circumstances does the investor make a profit? Under what circumstances will the...
-
Sherry rents her vacation home for 6 months and lives in it for 6 months during the year. Her gross rental income during the year is $4,000. Total real estate taxes for the home are $950, and...
-
Amy is a calendar-year taxpayer reporting on the cash basis. Please indicate how she should treat the following items for 2012: a. She makes a deductible contribution to an IRA on April 15,...
-
For each of the following situations, indicate whether the taxpayer(s) is (are) required to file a tax return for 2012. Explain your answer. a. Helen is a single taxpayer with interest income in 2012...
-
How can speakers use anxiety to their advantage?
-
What are common psychological, physical, and behavioral reactions associated with speech anxiety?
-
Describe strategies for making people the focus of your presentations.
Study smarter with the SolutionInn App