Question: Description of the Program In this assignment, you will need to design and implement a class Country (Country.java) that stores the name of the country,
Description of the Program In this assignment, you will need to design and implement a class Country (Country.java) that stores the name of the country, its population, and its area. Then write a program (LargestCountry.java) that reads countries from a coutrydata.txt and prints The country with the largest area.
The country with the largest population.
The country with the largest population density (people per square mile).
To make it concrete, the followings are the suggested tasks you need to perform: Stage1: In the rst le Country.java, create a class named Country that models a country. It should contain at least the followings (However, you can add any other methods if you like):
Private instance variables name, population, and area;
A constructor takes all three inputs (the name, population and area);
Three getter methods to return each of three instance variables (accessor method);
One getter method to return country population density (accessor method);
Three setter methods to change each of three instance variables (mutator);
A method printCountry that prints out the country information. Stage 2: In the second le LargestCountry.java, you are required to write methods for reading country data, and nding required information. The followings are suggested methods that you need to implement:
Method 1: readCountry /** Reads a country in from a file. @return all countries in an arraylist */ public static ArrayList
Method 2: countryWithLargestArea /** @return the country with the largest area */ public static Country countryWithLargestArea( ArrayList
Method 3: countryWithLargestPopulation /** @return the country with the largest population */ public static Country countryWithLargestPopulation( ArrayList
Method 4: countryWithLargestPopulationDensity /** @return the country with the largest population density */ public static Country countryWithLargestPopulationDensity( ArrayList
countrydata.txt contains ::
Country Population Area (in sq mi) Afghanistan 29835392 250000 Albania 2994667 11100 Algeria 34994937 919590 Andorra 84825 181 Angola 13338541 481351 Antigua_and_Barbuda 87884 171 Argentina 41769726 1068296 Armenia 2967975 11506 Australia 21766711 2967893 Austria 8217280 32382 Azerbaijan 8372373 33436 Bahamas 313312 5382 Bahrain 1214705 257 Bangladesh 158570535 55598 Barbados 286705 166 Belarus 9577552 80154 Belgium 10431477 11787 Belize 321115 8867 Benin 9325032 43483 Bhutan 708427 18147 Bolivia 10118683 424162 Bosnia_and_Herzegovina 4622163 19741 Botswana 2065398 231803 Brazil 203429773 3286470 Brunei 401890 2228 Bulgaria 7093635 42822 Burkina_Faso 16751455 105869 Burundi 10216190 10745 Cambodia 14701717 69900 Cameroon 19711291 183567 Canada 34030589 3855081 Cape_Verde 516100 1557 Central_African_Republic 4950027 240534 Chad 10758945 495752 Chile 16888760 292258 China 1336718015 3705386 Colombia 44725543 439733 Comoros 794683 838 Congo_Democratic_Republic_of_the 71712867 905563 Congo_Republic_of_the 4243929 132046 Costa_Rica 4576562 19730 Cote_d'Ivoire 21504162 124502 Croatia 4483804 21831 Cuba 11087330 42803 Cyprus 1120489 3571 Czech_Republic 10190213 30450 Denmark 5529888 16639 Djibouti 757074 8880 Dominica 72969 291 Dominican_Republic 9956648 18815 Ecuador 15007343 109483 Egypt 82079636 386660 El_Salvador 6071774 8124 Equatorial_Guinea 668225 10830 Eritrea 5939484 46842 Estonia 1282963 17462 Ethiopia 90873739 435184 Fiji 883125 7054 Finland 5259250 130558 France 65312249 211208 Gabon 1576665 103346 Gambia 1797860 4363 Georgia 4585874 26911 Germany 81471834 137846 Ghana 24791073 92456 Greece 10760136 50942 Grenada 108419 133 Guatemala 13824463 42042 Guinea 10601009 94925 Guinea-Bissau 1596677 13946 Guyana 744768 83000 Haiti 9719932 10714 Honduras 8143564 43278 Hungary 9976062 35919 Iceland 311058 39768 India 1189172906 1269338 Indonesia 245613043 741096 Iran 77891220 636293 Iraq 30399572 168753 Ireland 4670976 27135 Israel 7473052 8019 Italy 61016804 116305 Jamaica 2868380 4244 Japan 126475664 145882 Jordan 6508271 35637 Kazakhstan 15522373 1049150 Kenya 41070934 224961 Kiribati 100743 313 Korea_North 24457492 46540 Korea_South 48754657 38023 Kosovo 1825632 4211 Kuwait 2595628 6880 Kyrgyzstan 5587443 76641 Laos 6477211 91428 Latvia 2204708 24938 Lebanon 4143101 4015 Lesotho 1924886 11720 Liberia 3786764 43000 Libya 6597960 679358 Liechtenstein 35236 62 Lithuania 3535547 25174 Luxembourg 503302 998 Macedonia 2077328 9781 Madagascar 21926221 226656 Malawi 15879252 45745 Malaysia 28728607 127316 Maldives 394999 116 Mali 14159904 478764 Malta 408333 122 Marshall_Islands 67182 4577 Mauritania 3281634 397953 Mauritius 1303717 788 Mexico 113724226 761602 Micronesia_Federated_States_of 106836 271 Moldova 4314377 13067 Monaco 30539 1 Mongolia 3133318 603905 Montenegro 661807 5415 Morocco 31968361 172413 Mozambique 22948858 309494 Myanmar_(Burma) 53999804 261969 Namibia 2147585 318694 Nauru 9322 8 Nepal 29391883 54363 Netherlands 16847007 16033 New_Zealand 4290347 103737 Nicaragua 5666301 49998 Niger 16468886 489189 Nigeria 155215573 356667 Norway 4691849 125181 Oman 3027959 82031 Pakistan 187342721 310401 Palau 20956 177 Panama 3460462 30193 Papua_New_Guinea 6187591 178703 Paraguay 6459058 157046 Peru 29248943 496223 Philippines 101833938 115830 Poland 38441588 120728 Portugal 10760305 35672 Qatar 848016 4416 Romania 21904551 91669 Russia 138739892 6592735 Rwanda 11370425 10169 Saint_Kitts_and_Nevis 50314 101 Saint_Lucia 161557 238 Saint_Vincent_and_the_Grenadines 103869 150 Samoa 193161 1137 San_Marino 31817 24 Sao_Tome_and_Principe 179506 386 Saudi_Arabia 26131703 756981 Senegal 12643799 75749 Serbia 7310555 29913 Seychelles 89188 176 Sierra_Leone 5363669 27699 Singapore 4740737 267 Slovakia 5477038 18859 Slovenia 2000092 7827 Solomon_Islands 571890 10985 Somalia 9925640 246199 South_Africa 49004031 471008 South_Sudan 8260490 400367 Spain 46754784 194896 Sri_Lanka 21283913 25332 Sudan 45047502 728215 Suriname 491989 63039 Swaziland 1370424 6704 Sweden 9088728 173731 Switzerland 7639961 15942 Syria 22517750 71498 Taiwan 23071779 13892 Tajikistan 7627200 55251 Tanzania 42746620 364898 Thailand 66720153 198455 Timor-Leste 1177834 5641 Togo 6771993 21925 Tonga 105916 289 Trinidad_and_Tobago 1227505 1980 Tunisia 10629186 63170 Turkey 78785548 301382 Turkmenistan 4997503 188455 Tuvalu 10544 10 Uganda 34612250 91135 Ukraine 45134707 233089 United_Arab_Emirates 5148664 32000 United_Kingdom 62698362 94525 United_States 313232044 3718691 Uruguay 3308535 68039 Uzbekistan 28128600 172741 Vanuatu 224564 4710 Venezuela 27635743 352143 Vietnam 90549390 127243 Western_Sahara 507160 102703 Yemen 24133492 203849 Zambia 13881336 290584 Zimbabwe 12084304 150803
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
