Question: Java programming Question: (Please pay attention to the Additional Requriement at the end.) You are asked to implement a program which can display the population

Java programming

Question:

(Please pay attention to the Additional Requriement at the end.)

You are asked to implement a program which can display the population information of cities in different countries. The population information is stored in an input file. The format of the input file is as follows:

,, ,, ,, ...

...

,,

Sample txt file:

10 Sao Paulo,Brazil,22237472 Osaka,Japan,19110616 Mexico City,Mexico,21918936 Tokyo,Japan,37339804 Cairo,Egypt,21322750 Shanghai,China,27795702 Beijing,China,20896820 Delhi,India,31181376 Mumbai,India,20667656 Dhaka,Bangladesh,21741090

In the input file, the first line contains a positive integer, , which refers to the number of cities in the file; Each of the next lines contains the name of a city , the country , and the population separated by comma. A sample input file, population.txt, can be found in this question.

The program firstly reads the input file. After that, it displays a menu and supports three functions as follows:

  1. List all cities by country: This function will display the population information of all cities in the input file group by different countries.
  2. Search cities in a country: This function will display the population information of the cities given a country inputted by the user.
  3. Search the least-N populated cities: This function will display N countries with the lowest population, where N can be any positive integer and is inputted by the user.

The following shows a sample run of the program when using the sample input file above. The green text refers to the input by user.

Please choose:

1. List all cities by country

2. Search cities in a country

3. Search the least-N populated cities

0. QUIT

Your choice: 1

Cities in Brazil:

1: Sao Paulo(22237472)

Cities in Japan:

1: Osaka(19110616)

2: Tokyo(37339804)

Cities in Mexico:

1: Mexico City(21918936)

Cities in Egypt:

1: Cairo(21322750)

Cities in China:

1: Shanghai(27795702)

2: Beijing(20896820)

Cities in India:

1: Delhi(31181376)

2: Mumbai(20667656)

Cities in Bangladesh:

1: Dhaka(21741090)

Please choose:

1. List all cities by country

2. Search cities in a country

3. Search the least-N populated cities

0. QUIT

Your choice: 2

Enter a country > Japan

1: Osaka(19110616)

2: Tokyo(37339804)

Please choose:

1. List all cities by country

2. Search cities in a country

3. Search the least-N populated cities

0. QUIT

Your choice: 2

Enter a country > japan

1: Osaka(19110616)

2: Tokyo(37339804)

Please choose:

1. List all cities by country

2. Search cities in a country

3. Search the least-N populated cities

0. QUIT

Your choice: 2

Enter a country > South Africa

Cannot find cities in South Africa

Please choose:

1. List all cities by country

2. Search cities in a country

3. Search the least-N populated cities

0. QUIT

Your choice: 3

N? 3

1: Mumbai(20667656)

2: Osaka(19110616)

3: Beijing(20896820)

Please choose:

1. List all cities by country

2. Search cities in a country

3. Search the least-N populated cities

0. QUIT

Your choice: 3

N? 10

1: Sao Paulo(22237472)

2: Osaka(19110616)

3: Tokyo(37339804)

4: Mexico City(21918936)

5: Cairo(21322750)

6: Shanghai(27795702)

7: Beijing(20896820)

8: Delhi(31181376)

9: Mumbai(20667656)

10: Dhaka(21741090)

Please choose:

1. List all cities by country

2. Search cities in a country

3. Search the least-N populated cities

0. QUIT

Your choice: 3

N? 50

1: Sao Paulo(22237472)

2: Osaka(19110616)

3: Tokyo(37339804)

4: Mexico City(21918936)

5: Cairo(21322750)

6: Shanghai(27795702)

7: Beijing(20896820)

8: Delhi(31181376)

9: Mumbai(20667656)

10: Dhaka(21741090)

Only 10 cities found.

Please choose:

1. List all cities by country

2. Search cities in a country

3. Search the least-N populated cities

0. QUIT

Your choice: 0

Bye!

Additional Requirement:

  • You MUST create a class called Country to represent a country. This class must contain a private instance variable, which is an array of City, to store all cities of a country found from the file. This class may contain any other necessary instance variables and methods.
  • You MUST create a class called City to represent a city. This class must contain two instance variables: name of the city and population of the city ONLY. It may contain any necessary method.
  • You MUST create an array of Country to store a countries in the input file. You may assume there will be not more than 100 countries.
  • You MUST create a class called PopulationSystem which contains the main method to run the program.
  • You MUST NOT use any build-in data structures/classes like ArrayList, Set, HashMap, etc.
  • You MUST NOT use any third-party library or classes obtained from any sources.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!