Download Category:

Population.zip - (67.63 KB)

Write a program that uses the ArrayList class to store objects. Do NOT use static
arrays that we used in earlier chapters. Listing 11.8 on page 433 may be helpful. Write a
program to store the name of a city and its population using 2 ArrayLists (one to hold
the name and the other to hold the population). A sample input might look like:
London 8000000
Boston 600000
Las Vegas 580000
Once you have the data in the arrays, display the size of the arrays, ask the user to
enter a city name and check if the name exists in the array. Allow the user to add more
cities and to be able to remove cities. Display the contents of the arrays using its
toString method. Allow the user to enter a city name and display the corresponding
population. If the input city name does not exist, display a message. Calculate and
display the total population of all the cities. Sort the data by population in ascending
order and display the data in the original order and the sorted order. You may use any
sorting algorithm that you like.

Write a Review

Get a fresh solution of this question. Ask it now to our experts.

Ask Your Question

We have verified professionals who are ready to answer your question.


Save Time and Money

We choose experts who can quickly answer your question and that suit your budget.


Get Your Answer

Your satisfaction is 100% guaranteed. You can keep on asking questions until you get the answer you need.