Skip to content

Commit 4978651

Browse files
committed
Added base case for zero by zero division leading to NaN outputs as reported in Bug #76
1 parent 7c63a26 commit 4978651

4 files changed

Lines changed: 295 additions & 16 deletions

File tree

reports/ContinentUrbanReport.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
| Continent | Population | Urban Population | Urbanisation Percentage |
2-
| --- | --- | --- | --- |
3-
| Africa | 100 | 0 | 0 |
4-
| Antarctica | 100 | 0 | 0 |
5-
| Asia | 100 | 0 | 0 |
6-
| Europe | 100 | 0 | 0 |
7-
| North America | 100 | 0 | 0 |
8-
| Oceania | 100 | 0 | 0 |
9-
| South America | 100 | 0 | 0 |
1+
| Continent | Population | Urban Population | Urbanisation Percentage |
2+
| --- | --- | --- | --- |
3+
| Africa | 784,475,000 | 135,838,579 | 17.32 |
4+
| Antarctica | 0 | 0 | 0 |
5+
| Asia | 3,705,025,700 | 697,604,103 | 18.83 |
6+
| Europe | 730,074,600 | 241,942,813 | 33.14 |
7+
| North America | 482,993,000 | 168,250,381 | 34.83 |
8+
| Oceania | 30,401,150 | 13,886,149 | 45.68 |
9+
| South America | 345,780,000 | 172,037,859 | 49.75 |

reports/CountryUrbanReport.md

Lines changed: 241 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,241 @@
1-
| Country | Population | Urban Population | Urbanisation Percentage |
2-
| --- | --- | --- | --- |
1+
| Country | Population | Urban Population | Urbanisation Percentage |
2+
| --- | --- | --- | --- |
3+
| Afghanistan | 22,720,000 | 2,332,100 | 10.26 |
4+
| Albania | 3,401,200 | 270,000 | 7.94 |
5+
| Algeria | 31,471,000 | 5,192,179 | 16.5 |
6+
| American Samoa | 68,000 | 7,523 | 11.06 |
7+
| Andorra | 78,000 | 21,189 | 27.17 |
8+
| Angola | 12,878,000 | 2,561,600 | 19.89 |
9+
| Anguilla | 8,000 | 1,556 | 19.45 |
10+
| Antarctica | 0 | 0 | 0 |
11+
| Antigua and Barbuda | 68,000 | 24,000 | 35.29 |
12+
| Argentina | 37,032,000 | 19,996,563 | 54 |
13+
| Armenia | 3,520,000 | 1,633,100 | 46.39 |
14+
| Aruba | 103,000 | 29,034 | 28.19 |
15+
| Australia | 18,886,000 | 11,313,666 | 59.91 |
16+
| Austria | 8,091,800 | 2,384,273 | 29.47 |
17+
| Azerbaijan | 7,734,000 | 2,464,000 | 31.86 |
18+
| Bahamas | 307,000 | 172,000 | 56.03 |
19+
| Bahrain | 617,000 | 148,000 | 23.99 |
20+
| Bangladesh | 129,155,000 | 8,569,906 | 6.64 |
21+
| Barbados | 270,000 | 6,070 | 2.25 |
22+
| Belarus | 10,236,000 | 4,741,000 | 46.32 |
23+
| Belgium | 10,239,000 | 1,609,322 | 15.72 |
24+
| Belize | 241,000 | 62,915 | 26.11 |
25+
| Benin | 6,097,000 | 968,503 | 15.88 |
26+
| Bermuda | 65,000 | 3,000 | 4.62 |
27+
| Bhutan | 2,124,000 | 22,000 | 1.04 |
28+
| Bolivia | 8,329,000 | 3,378,644 | 40.56 |
29+
| Bosnia and Herzegovina | 3,972,000 | 599,106 | 15.08 |
30+
| Botswana | 1,622,000 | 314,822 | 19.41 |
31+
| Bouvet Island | 0 | 0 | 0 |
32+
| Brazil | 170,115,000 | 85,876,862 | 50.48 |
33+
| British Indian Ocean Territory | 0 | 0 | 0 |
34+
| Brunei | 328,000 | 21,484 | 6.55 |
35+
| Bulgaria | 8,190,900 | 2,696,915 | 32.93 |
36+
| Burkina Faso | 11,937,000 | 1,229,000 | 10.3 |
37+
| Burundi | 6,695,000 | 300,000 | 4.48 |
38+
| Cambodia | 11,168,000 | 805,055 | 7.21 |
39+
| Cameroon | 15,085,000 | 3,522,554 | 23.35 |
40+
| Canada | 31,147,000 | 12,673,840 | 40.69 |
41+
| Cape Verde | 428,000 | 94,800 | 22.15 |
42+
| Cayman Islands | 38,000 | 19,600 | 51.58 |
43+
| Central African Republic | 3,615,000 | 524,000 | 14.5 |
44+
| Chad | 7,651,000 | 630,465 | 8.24 |
45+
| Chile | 15,211,000 | 9,717,970 | 63.89 |
46+
| China | 1,277,558,000 | 175,953,614 | 13.77 |
47+
| Christmas Island | 2,500 | 700 | 28 |
48+
| Cocos (Keeling) Islands | 600 | 670 | 111.67 |
49+
| Colombia | 42,321,000 | 20,250,990 | 47.85 |
50+
| Comoros | 578,000 | 36,000 | 6.23 |
51+
| Congo | 2,943,000 | 1,450,000 | 49.27 |
52+
| Congo, The Democratic Republic of the | 51,654,000 | 9,864,615 | 19.1 |
53+
| Cook Islands | 20,000 | 11,900 | 59.5 |
54+
| Costa Rica | 4,023,000 | 339,131 | 8.43 |
55+
| Côte d’Ivoire | 14,786,000 | 3,191,137 | 21.58 |
56+
| Croatia | 4,473,000 | 1,168,883 | 26.13 |
57+
| Cuba | 11,201,000 | 4,629,925 | 41.33 |
58+
| Cyprus | 754,700 | 349,400 | 46.3 |
59+
| Czech Republic | 10,278,100 | 2,634,711 | 25.63 |
60+
| Denmark | 5,330,000 | 1,215,945 | 22.81 |
61+
| Djibouti | 638,000 | 383,000 | 60.03 |
62+
| Dominica | 71,000 | 16,243 | 22.88 |
63+
| Dominican Republic | 8,495,000 | 2,438,276 | 28.7 |
64+
| East Timor | 885,000 | 47,900 | 5.41 |
65+
| Ecuador | 12,646,000 | 5,744,142 | 45.42 |
66+
| Egypt | 68,470,000 | 20,083,079 | 29.33 |
67+
| El Salvador | 6,276,000 | 1,138,231 | 18.14 |
68+
| Equatorial Guinea | 453,000 | 40,000 | 8.83 |
69+
| Eritrea | 3,850,000 | 431,000 | 11.19 |
70+
| Estonia | 1,439,200 | 505,227 | 35.1 |
71+
| Ethiopia | 62,565,000 | 3,190,334 | 5.1 |
72+
| Falkland Islands | 2,000 | 1,636 | 81.8 |
73+
| Faroe Islands | 43,000 | 14,542 | 33.82 |
74+
| Fiji Islands | 817,000 | 77,366 | 9.47 |
75+
| Finland | 5,171,300 | 1,532,919 | 29.64 |
76+
| France | 59,225,700 | 9,244,494 | 15.61 |
77+
| French Guiana | 181,000 | 50,699 | 28.01 |
78+
| French Polynesia | 235,000 | 51,441 | 21.89 |
79+
| French Southern territories | 0 | 0 | 0 |
80+
| Gabon | 1,226,000 | 419,000 | 34.18 |
81+
| Gambia | 1,305,000 | 144,926 | 11.11 |
82+
| Georgia | 4,968,000 | 1,880,900 | 37.86 |
83+
| Germany | 82,164,700 | 26,245,483 | 31.94 |
84+
| Ghana | 20,212,000 | 1,819,889 | 9 |
85+
| Gibraltar | 25,000 | 27,025 | 108.1 |
86+
| Greece | 10,545,700 | 1,972,843 | 18.71 |
87+
| Greenland | 56,000 | 13,445 | 24.01 |
88+
| Grenada | 94,000 | 4,621 | 4.92 |
89+
| Guadeloupe | 456,000 | 75,380 | 16.53 |
90+
| Guam | 168,000 | 10,639 | 6.33 |
91+
| Guatemala | 11,385,000 | 1,225,188 | 10.76 |
92+
| Guinea | 7,430,000 | 1,090,610 | 14.68 |
93+
| Guinea-Bissau | 1,213,000 | 241,000 | 19.87 |
94+
| Guyana | 861,000 | 254,000 | 29.5 |
95+
| Haiti | 8,222,000 | 1,517,338 | 18.45 |
96+
| Heard Island and McDonald Islands | 0 | 0 | 0 |
97+
| Holy See (Vatican City State) | 1,000 | 455 | 45.5 |
98+
| Honduras | 6,485,000 | 1,287,000 | 19.85 |
99+
| Hong Kong | 6,782,000 | 3,300,633 | 48.67 |
100+
| Hungary | 10,043,200 | 2,953,310 | 29.41 |
101+
| Iceland | 279,000 | 109,184 | 39.13 |
102+
| India | 1,013,662,000 | 123,298,526 | 12.16 |
103+
| Indonesia | 212,107,000 | 37,485,695 | 17.67 |
104+
| Iran | 67,702,000 | 26,032,990 | 38.45 |
105+
| Iraq | 23,115,000 | 8,926,041 | 38.62 |
106+
| Ireland | 3,775,100 | 609,041 | 16.13 |
107+
| Israel | 6,217,000 | 2,813,000 | 45.25 |
108+
| Italy | 57,680,000 | 15,087,019 | 26.16 |
109+
| Jamaica | 2,583,000 | 314,140 | 12.16 |
110+
| Japan | 126,714,000 | 77,965,107 | 61.53 |
111+
| Jordan | 5,083,000 | 1,847,677 | 36.35 |
112+
| Kazakstan | 16,223,000 | 5,484,200 | 33.81 |
113+
| Kenya | 30,080,000 | 3,522,793 | 11.71 |
114+
| Kiribati | 83,000 | 7,281 | 8.77 |
115+
| Kuwait | 1,972,000 | 261,252 | 13.25 |
116+
| Kyrgyzstan | 4,699,000 | 812,100 | 17.28 |
117+
| Laos | 5,433,000 | 628,452 | 11.57 |
118+
| Latvia | 2,424,200 | 968,596 | 39.96 |
119+
| Lebanon | 3,282,000 | 1,340,000 | 40.83 |
120+
| Lesotho | 2,153,000 | 297,000 | 13.79 |
121+
| Liberia | 3,154,000 | 850,000 | 26.95 |
122+
| Libyan Arab Jamahiriya | 5,605,000 | 2,697,007 | 48.12 |
123+
| Liechtenstein | 32,300 | 10,389 | 32.16 |
124+
| Lithuania | 3,698,500 | 1,473,317 | 39.84 |
125+
| Luxembourg | 435,700 | 80,700 | 18.52 |
126+
| Macao | 473,000 | 437,500 | 92.49 |
127+
| Macedonia | 2,024,000 | 444,299 | 21.95 |
128+
| Madagascar | 15,942,000 | 1,123,161 | 7.05 |
129+
| Malawi | 10,925,000 | 914,119 | 8.37 |
130+
| Malaysia | 22,244,000 | 4,605,141 | 20.7 |
131+
| Maldives | 286,000 | 71,000 | 24.83 |
132+
| Mali | 11,234,000 | 809,552 | 7.21 |
133+
| Malta | 380,200 | 28,518 | 7.5 |
134+
| Marshall Islands | 64,000 | 28,000 | 43.75 |
135+
| Martinique | 395,000 | 94,050 | 23.81 |
136+
| Mauritania | 2,670,000 | 764,900 | 28.65 |
137+
| Mauritius | 1,158,000 | 337,280 | 29.13 |
138+
| Mayotte | 149,000 | 12,000 | 8.05 |
139+
| Mexico | 98,881,000 | 59,752,521 | 60.43 |
140+
| Micronesia, Federated States of | 119,000 | 30,600 | 25.71 |
141+
| Moldova | 4,380,000 | 1,193,300 | 27.24 |
142+
| Monaco | 34,000 | 14,388 | 42.32 |
143+
| Mongolia | 2,662,000 | 773,700 | 29.06 |
144+
| Montserrat | 11,000 | 2,000 | 18.18 |
145+
| Morocco | 28,351,000 | 8,757,562 | 30.89 |
146+
| Mozambique | 19,680,000 | 3,143,145 | 15.97 |
147+
| Myanmar | 45,611,000 | 6,203,000 | 13.6 |
148+
| Namibia | 1,726,000 | 169,000 | 9.79 |
149+
| Nauru | 12,000 | 4,609 | 38.41 |
150+
| Nepal | 23,930,000 | 1,132,403 | 4.73 |
151+
| Netherlands | 15,864,000 | 5,180,049 | 32.65 |
152+
| Netherlands Antilles | 217,000 | 2,345 | 1.08 |
153+
| New Caledonia | 214,000 | 76,293 | 35.65 |
154+
| New Zealand | 3,862,000 | 1,847,600 | 47.84 |
155+
| Nicaragua | 5,074,000 | 1,269,223 | 25.01 |
156+
| Niger | 10,730,000 | 653,857 | 6.09 |
157+
| Nigeria | 111,506,000 | 17,366,900 | 15.57 |
158+
| Niue | 2,000 | 682 | 34.1 |
159+
| Norfolk Island | 2,000 | 800 | 40 |
160+
| North Korea | 24,039,000 | 6,476,751 | 26.94 |
161+
| Northern Mariana Islands | 78,000 | 9,200 | 11.79 |
162+
| Norway | 4,478,500 | 1,100,028 | 24.56 |
163+
| Oman | 2,542,000 | 537,096 | 21.13 |
164+
| Pakistan | 156,483,000 | 31,546,745 | 20.16 |
165+
| Palau | 19,000 | 12,000 | 63.16 |
166+
| Palestine | 3,101,000 | 902,360 | 29.1 |
167+
| Panama | 2,856,000 | 786,755 | 27.55 |
168+
| Papua New Guinea | 4,807,000 | 247,000 | 5.14 |
169+
| Paraguay | 5,496,000 | 1,020,020 | 18.56 |
170+
| Peru | 25,662,000 | 12,147,242 | 47.34 |
171+
| Philippines | 75,967,000 | 30,934,791 | 40.72 |
172+
| Pitcairn | 50 | 42 | 84 |
173+
| Poland | 38,653,600 | 11,687,431 | 30.24 |
174+
| Portugal | 9,997,600 | 1,145,011 | 11.45 |
175+
| Puerto Rico | 3,869,000 | 1,564,174 | 40.43 |
176+
| Qatar | 599,000 | 355,000 | 59.27 |
177+
| Réunion | 699,000 | 131,480 | 18.81 |
178+
| Romania | 22,455,500 | 7,469,006 | 33.26 |
179+
| Russian Federation | 146,934,000 | 69,150,700 | 47.06 |
180+
| Rwanda | 7,733,000 | 286,000 | 3.7 |
181+
| Saint Helena | 6,000 | 1,500 | 25 |
182+
| Saint Kitts and Nevis | 38,000 | 11,600 | 30.53 |
183+
| Saint Lucia | 154,000 | 2,301 | 1.49 |
184+
| Saint Pierre and Miquelon | 7,000 | 5,808 | 82.97 |
185+
| Saint Vincent and the Grenadines | 114,000 | 17,100 | 15 |
186+
| Samoa | 180,000 | 35,900 | 19.94 |
187+
| San Marino | 27,000 | 7,096 | 26.28 |
188+
| Sao Tome and Principe | 147,000 | 49,541 | 33.7 |
189+
| Saudi Arabia | 21,607,000 | 10,636,700 | 49.23 |
190+
| Senegal | 9,481,000 | 2,770,458 | 29.22 |
191+
| Seychelles | 77,000 | 41,000 | 53.25 |
192+
| Sierra Leone | 4,854,000 | 850,000 | 17.51 |
193+
| Singapore | 3,567,000 | 4,017,733 | 112.64 |
194+
| Slovakia | 5,398,700 | 784,143 | 14.52 |
195+
| Slovenia | 1,987,800 | 386,518 | 19.44 |
196+
| Solomon Islands | 444,000 | 50,100 | 11.28 |
197+
| Somalia | 10,097,000 | 1,177,000 | 11.66 |
198+
| South Africa | 40,377,000 | 15,196,370 | 37.64 |
199+
| South Georgia and the South Sandwich Islands | 0 | 0 | 0 |
200+
| South Korea | 46,844,000 | 38,999,893 | 83.25 |
201+
| Spain | 39,441,700 | 16,669,189 | 42.26 |
202+
| Sri Lanka | 18,827,000 | 1,545,000 | 8.21 |
203+
| Sudan | 29,490,000 | 4,752,187 | 16.11 |
204+
| Suriname | 417,000 | 112,000 | 26.86 |
205+
| Svalbard and Jan Mayen | 3,200 | 1,438 | 44.94 |
206+
| Swaziland | 1,008,000 | 61,000 | 6.05 |
207+
| Sweden | 8,861,400 | 2,891,431 | 32.63 |
208+
| Switzerland | 7,160,400 | 914,200 | 12.77 |
209+
| Syria | 16,125,000 | 4,477,784 | 27.77 |
210+
| Taiwan | 22,256,000 | 13,569,336 | 60.97 |
211+
| Tajikistan | 6,188,000 | 685,500 | 11.08 |
212+
| Tanzania | 33,517,000 | 2,944,034 | 8.78 |
213+
| Thailand | 61,399,000 | 7,953,161 | 12.95 |
214+
| Togo | 4,629,000 | 375,000 | 8.1 |
215+
| Tokelau | 2,000 | 300 | 15 |
216+
| Tonga | 99,000 | 22,400 | 22.63 |
217+
| Trinidad and Tobago | 1,295,000 | 99,997 | 7.72 |
218+
| Tunisia | 9,586,000 | 1,798,500 | 18.76 |
219+
| Turkey | 66,591,000 | 28,327,028 | 42.54 |
220+
| Turkmenistan | 4,459,000 | 972,600 | 21.81 |
221+
| Turks and Caicos Islands | 17,000 | 4,800 | 28.24 |
222+
| Tuvalu | 12,000 | 4,600 | 38.33 |
223+
| Uganda | 21,778,000 | 890,800 | 4.09 |
224+
| Ukraine | 50,456,000 | 20,074,000 | 39.79 |
225+
| United Arab Emirates | 2,441,000 | 1,728,336 | 70.8 |
226+
| United Kingdom | 59,623,400 | 22,436,673 | 37.63 |
227+
| United States | 278,357,000 | 78,625,774 | 28.25 |
228+
| United States Minor Outlying Islands | 0 | 0 | 0 |
229+
| Uruguay | 3,337,000 | 1,236,000 | 37.04 |
230+
| Uzbekistan | 24,318,000 | 5,183,900 | 21.32 |
231+
| Vanuatu | 190,000 | 33,700 | 17.74 |
232+
| Venezuela | 24,170,000 | 12,251,091 | 50.69 |
233+
| Vietnam | 79,832,000 | 9,364,813 | 11.73 |
234+
| Virgin Islands, British | 21,000 | 8,000 | 38.1 |
235+
| Virgin Islands, U.S. | 93,000 | 13,000 | 13.98 |
236+
| Wallis and Futuna | 15,000 | 1,137 | 7.58 |
237+
| Western Sahara | 293,000 | 169,000 | 57.68 |
238+
| Yemen | 18,112,000 | 1,743,700 | 9.63 |
239+
| Yugoslavia | 10,640,000 | 2,189,507 | 20.58 |
240+
| Zambia | 9,169,000 | 2,473,500 | 26.98 |
241+
| Zimbabwe | 11,669,000 | 2,730,420 | 23.4 |

reports/RegionalUrbanReport.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
1-
| Region | Population | Urban Population | Urbanisation Percentage |
2-
| --- | --- | --- | --- |
1+
| Region | Population | Urban Population | Urbanisation Percentage |
2+
| --- | --- | --- | --- |
3+
| Caribbean | 38,140,000 | 11,067,550 | 29.02 |
4+
| Southern and Central Asia | 1,490,776,000 | 207,688,970 | 13.93 |
5+
| Central Africa | 95,652,000 | 19,061,775 | 19.93 |
6+
| Southern Europe | 144,674,200 | 40,016,658 | 27.66 |
7+
| Middle East | 188,380,700 | 70,371,374 | 37.36 |
8+
| South America | 345,780,000 | 172,037,859 | 49.75 |
9+
| Polynesia | 633,050 | 135,925 | 21.47 |
10+
| Antarctica | 0 | 0 | 0 |
11+
| Australia and New Zealand | 22,753,100 | 13,163,436 | 57.85 |
12+
| Western Europe | 183,247,600 | 45,683,298 | 24.93 |
13+
| Eastern Africa | 246,999,000 | 24,067,066 | 9.74 |
14+
| Western Africa | 221,672,000 | 33,222,032 | 14.99 |
15+
| Eastern Europe | 307,026,000 | 123,384,516 | 40.19 |
16+
| Central America | 135,221,000 | 65,860,964 | 48.71 |
17+
| North America | 309,632,000 | 91,321,867 | 29.49 |
18+
| Southeast Asia | 518,541,000 | 102,067,225 | 19.68 |
19+
| Southern Africa | 46,886,000 | 16,038,192 | 34.21 |
20+
| Eastern Asia | 1,507,328,000 | 317,476,534 | 21.06 |
21+
| Nordic Countries | 24,166,400 | 6,865,487 | 28.41 |
22+
| Northern Africa | 173,266,000 | 43,449,514 | 25.08 |
23+
| Baltic Countries | 7,561,900 | 2,947,140 | 38.97 |
24+
| Melanesia | 6,472,000 | 484,459 | 7.49 |
25+
| Micronesia | 543,000 | 102,329 | 18.85 |
26+
| British Islands | 63,398,500 | 23,045,714 | 36.35 |
27+
| Micronesia/Caribbean | 0 | 0 | 0 |

src/main/java/com/napier/sem/UrbanReport.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,12 @@ public void generateContinentReport(Connection con, String[] continents, String
282282
for (String continent : continents){
283283
getPopulationOfContinent(con,continent);
284284
getUrbanPopulationOfContinent(con,continent);
285-
percentage = (urbanPopulation / population) * 100;
285+
if (population == 0) {
286+
percentage = 0;
287+
} else {
288+
percentage = (urbanPopulation * 100.0) / population;
289+
}
290+
286291
sb.append("| ")
287292
.append(continent).append(" | ")
288293
.append(numberFormat.format(population)).append(" | ")
@@ -318,7 +323,12 @@ public void generateRegionReport(Connection con, List<String> regions, String fi
318323
for (String region : regions){
319324
getPopulationOfRegion(con,region);
320325
getUrbanPopulationOfRegion(con,region);
321-
percentage = (urbanPopulation / population) * 100;
326+
if (population == 0) {
327+
percentage = 0;
328+
} else {
329+
percentage = (urbanPopulation * 100.0) / population;
330+
}
331+
322332
sb.append("| ")
323333
.append(region).append(" | ")
324334
.append(numberFormat.format(population)).append(" | ")
@@ -354,7 +364,12 @@ public void generateCountryReport(Connection con, List<String> countries, String
354364
for (String country : countries){
355365
getPopulationOfCountry(con,country);
356366
getUrbanPopulationOfCountry(con,country);
357-
percentage = (urbanPopulation / population) * 100;
367+
if (population == 0) {
368+
percentage = 0;
369+
} else {
370+
percentage = (urbanPopulation * 100.0) / population;
371+
}
372+
358373
sb.append("| ")
359374
.append(country).append(" | ")
360375
.append(numberFormat.format(population)).append(" | ")

0 commit comments

Comments
 (0)