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
-
Discuss the lean production strategy and the attributes derived from its implementation.
-
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...
-
What are the primary considerations in tool selection?
-
Develop a checklist of rules you can use to help you determine whether a flowchart or pseudocode segment is structured.
-
Should every board have directors and officers insurance? Why or why not?
-
At the completion of the current fiscal year ending December 31, the balance of Accounts Receivable for Yangs Gift Shop was $30,000. Credit sales for the year were $355,200. REQUIRED Make the...
-
Find an equation of the tangent line to the curve y = 5 cos x at the point ( \ pi , 5 . )
-
Keenan is purchasing a new boat that sells for $56,214, including taxes and fees. He receives $17,000 as a trade-in on his old boat and uses the money as a down payment. Keenan finances the balance...
-
Critically discuss the impact of social media on the role of leadership and human capital.
-
An employee works for a company that pays $ 1 5 per hour, double time and one - half overtime and has a standard workweek of 4 4 hours. What would be the gross pay for an employee that worked 4 5...
-
You are working on a bid for a 7-year contract. Thus far, you have determined that you will need $159,000 for fixed assets that will be depreciated straight-line to zero over the life of the project...
-
Melun Limited is considering producing a new line of high quality snowboards. The company will incur $62 in variable product costs for each snowboard produced. Fixed manufacturing overhead costs...
-
How do we determine the tax consequences of a disposition of a partnership interest? Please discuss from the buyer's and the seller's perspectives. How is the gain or loss determined?
-
Ivanhoe Company's accounting records reflect the following inventories: Jan. 1, 2022 Dec. 31, 2022 Raw materials inventory $260,000 $320,000 Work in process inventory 160,000 300,000 Finished goods...
-
1. A projectile is launched in a vertical plane, at an angle 0 with initial velocity vo. It must be caught in a frictionless circular tube of radius R in such a way that the trajectory of the...
-
Use this circle graph to answer following Exercises. 1. What fraction of areas maintained by the National Park Service are designated as National Recreation Areas? 2. What fraction of areas...
-
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...
-
During the past year, Lite Company had net income of \(\$ 5\) million, and Scanlon Company had net income of \(\$ 8\) million. Both companies manufacture electrical components for the construction...
-
Blare Company had a return on sales of 6.5 percent and an asset turnover of 2.40. What is Blare's return on assets?
-
Under what circumstances can the return on sales be used to assess the profitability of a company? Can this ratio be used to compare the profitability of companies from different industries? Explain.
Study smarter with the SolutionInn App