***PLEASE JUST WRITE THE DOCUMENTATION COMMENTS ABOUT THE PROGRAMS*** Assume tha
ID: 3703076 • Letter: #
Question
***PLEASE JUST WRITE THE DOCUMENTATION COMMENTS ABOUT THE PROGRAMS*** Assume that the population of Mexico is 121 million and that the population increases 1.05% annually (new population = current population x 1.0105). Assume that the population of the United States is 315 million and that the population is reduced 0.16% annually (new population = current population x 0.9984) . Assume that the population of Japan is 127 million and that the population increases 1.01% annually (new population = current population x 1.0101). Write an application that displays the populations for the three countries every year until both Mexican and Japanese populations pass US population. Display the number of years it took for Mexico’s and Japan’s populations to exceed that of the United States. Use both while loop and for loop to accomplish the task. Save the two files (one for each type of loop) as Population_while.java and Population_for.java
Explanation / Answer
Please find my implementation:
Plase let me know if you need more information:-
============================================
Population_while.java
============================================
import java.text.NumberFormat;
import java.util.Locale;
public class Population_while {
public static void main(String[] args){
// declaring variables
double pop_Mex = 121000000;
double pop_US = 315000000;
double pop_JAPAN = 127000000;
int year = 2000;
int year_tmp = year;
NumberFormat nf = NumberFormat.getInstance(Locale.US);
System.out.println("Year Mexico US JAPAN");
System.out.println("================================================================================");
while(true){
pop_Mex *= 1.0105;
pop_US *= 0.9984;
pop_JAPAN *= 1.0101;
System.out.print(year +" ");
System.out.print(nf.format(pop_Mex)+" ");
System.out.print(nf.format(pop_US)+" ");
System.out.println(nf.format(pop_JAPAN)+" ");
if(pop_US<pop_Mex && pop_US<pop_JAPAN){
System.out.println("================================================================================");
System.out.println("WHILE: Now MEX and JAPAN Population are more than US and it took: "+(year-year_tmp)+" Years");
System.out.println("================================================================================");
break;
}
year++;
}
}
}
====================================================
Population_for.java
====================================================
import java.text.NumberFormat;
import java.util.Locale;
public class Population_for {
public static void main(String[] args){
double pop_Mex = 121000000;
double pop_JAPAN = 127000000;
int year = 2000;
int year_tmp = year;
NumberFormat nf = NumberFormat.getInstance(Locale.US);
System.out.println("Year Mexico US JAPAN");
System.out.println("================================================================================");
for(double pop_US = 315000000;(pop_US>pop_Mex || pop_US>pop_JAPAN);){
pop_US *= 0.9984;
pop_Mex *= 1.0105;
pop_JAPAN *= 1.0101;
System.out.print(year +" ");
System.out.print(nf.format(pop_Mex)+" ");
System.out.print(nf.format(pop_US)+" ");
System.out.println(nf.format(pop_JAPAN)+" ");
year++;
}
System.out.println("================================================================================");
System.out.println("FOR: Now MEX and JAPAN Population are more than US and it took: "+(year-1-year_tmp)+" Years");
System.out.println("================================================================================");
}
}
==============================================================
WHILE_OUTPUT :-
===============================================================
Year Mexico US JAPAN
================================================================================
2000 122,270,500 314,496,000 128,282,700
2001 123,554,340.25 313,992,806.4 129,578,355.27
2002 124,851,660.823 313,490,417.91 130,887,096.658
2003 126,162,603.261 312,988,833.241 132,209,056.334
2004 127,487,310.596 312,488,051.108 133,544,367.803
2005 128,825,927.357 311,988,070.226 134,893,165.918
2006 130,178,599.594 311,488,889.314 136,255,586.894
2007 131,545,474.89 310,990,507.091 137,631,768.322
2008 132,926,702.376 310,492,922.28 139,021,849.182
2009 134,322,432.751 309,996,133.604 140,425,969.858
2010 135,732,818.295 309,500,139.79 141,844,272.154
2011 137,158,012.887 309,004,939.566 143,276,899.303
2012 138,598,172.022 308,510,531.663 144,723,995.986
2013 140,053,452.829 308,016,914.812 146,185,708.345
2014 141,524,014.083 307,524,087.749 147,662,183.999
2015 143,010,016.231 307,032,049.208 149,153,572.058
2016 144,511,621.402 306,540,797.93 150,660,023.136
2017 146,028,993.426 306,050,332.653 152,181,689.369
2018 147,562,297.857 305,560,652.121 153,718,724.432
2019 149,111,701.985 305,071,755.077 155,271,283.549
2020 150,677,374.856 304,583,640.269 156,839,523.513
2021 152,259,487.292 304,096,306.445 158,423,602.7
2022 153,858,211.908 303,609,752.354 160,023,681.087
2023 155,473,723.133 303,123,976.751 161,639,920.266
2024 157,106,197.226 302,638,978.388 163,272,483.461
2025 158,755,812.297 302,154,756.022 164,921,535.544
2026 160,422,748.326 301,671,308.413 166,587,243.053
2027 162,107,187.183 301,188,634.319 168,269,774.208
2028 163,809,312.649 300,706,732.504 169,969,298.927
2029 165,529,310.432 300,225,601.732 171,685,988.846
2030 167,267,368.191 299,745,240.77 173,420,017.334
2031 169,023,675.557 299,265,648.384 175,171,559.509
2032 170,798,424.151 298,786,823.347 176,940,792.26
2033 172,591,807.604 298,308,764.43 178,727,894.262
2034 174,404,021.584 297,831,470.407 180,533,045.994
2035 176,235,263.811 297,354,940.054 182,356,429.758
2036 178,085,734.081 296,879,172.15 184,198,229.699
continue.......
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.