Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume that the population of Mexico is 121 million and that the population incr

ID: 3699052 • Letter: A

Question

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

Population_while.java

public class Population_while {

public static void main(String[] args) {

double Mexico_Population = 121;

double United_Population = 315;

double Japan_Population = 127;

int year = 0;

while (Mexico_Population < United_Population

|| Japan_Population < United_Population) {

year++;

Mexico_Population = Mexico_Population * 1.0105;

United_Population = United_Population * 0.9984;

Japan_Population = Japan_Population * 1.0101;

}

System.out

.println("The number of years it took for Mexico’s and Japan’s populations to exceed that of the United States: "

+ year);

}

}

Output:

The number of years it took for Mexico’s and Japan’s populations to exceed that of the United States: 80

Population_for.java

public class Population_for {

public static void main(String[] args) {

double Mexico_Population = 121;

double United_Population = 315;

double Japan_Population = 127;

int year = 0;

for(year =0;Mexico_Population < United_Population

|| Japan_Population < United_Population; year++) {

Mexico_Population = Mexico_Population * 1.0105;

United_Population = United_Population * 0.9984;

Japan_Population = Japan_Population * 1.0101;

}

System.out

.println("The number of years it took for Mexico’s and Japan’s populations to exceed that of the United States: "

+ year);

}

}

Output:

The number of years it took for Mexico’s and Japan’s populations to exceed that of the United States: 80

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote