Question

In: Computer Science

Assume that the population of Mexico is 128 million and that the population increases 1.01 percent...

Assume that the population of Mexico is 128 million and that the population increases 1.01 percent annually. Assume that the population of the United States is 323 million and that the population is reduced 0.15 percent annually. Write an application that displays the populations for the two countries every year until the population of Mexico exceeds that of the United States, and display the number of years it took. Save the file as Population.java.

Solutions

Expert Solution

Population.java file:


public class Population {
  
   private static double Mexico = 128.0; // initial population of Mexico in million
   private static double Mexico_growth_rate = 1.01; // population increase by this rate every year
   private static double UnitedStates = 323.0; // initial population of United States in million
   private static double US_growth_rate = -0.15; // negative growth rate as population decrease by this rate each year
   private static int count = 0; // variable to hold number of years taken
  
   //main method to run the program
   public static void main(String args[]) {
       // print header for output
       String s = String.format("%s %12s %22s", "Year", "Mexico", "United States"); // formating string for output
       System.out.println(s);
       while(true) {
           // print out the population for current year
           print(count, Mexico, UnitedStates);
           // check if population of Mexico exceeds that of the United States
           if(Mexico > UnitedStates) {
               // break the loop as condition for program ending are met
               break;
           }
           else {
               // calculate Mexico's population
               Mexico = Mexico + (Mexico*Mexico_growth_rate/100.0);
               // calculate United States's population
               UnitedStates = UnitedStates + (UnitedStates*US_growth_rate/100.0);
               // increase count by 1
               count++;
           }
       }//end of while loop
       // print result message
       System.out.println();
       System.out.print("It takes ");
       System.out.print(count);
       System.out.println(" years for population of Mexico to exceed that of the United States");
   }

   private static void print(int year, double mexico, double unitedStates) {
       // formating string for output
       String str = String.format("%2d %10.2f %s %10.2f %s", year, mexico, "million", unitedStates, "million");
       // print populations
       System.out.println(str);  
   }

}



Related Solutions

Assume that the population of Mexico is 128 million and that the population increases 1.01 percent...
Assume that the population of Mexico is 128 million and that the population increases 1.01 percent annually. Assume that the population of the United States is 323 million and that the population is reduced 0.15 percent annually. Write an application that displays the populations for the two countries every year until the population of Mexico exceeds that of the United States, and display The population of Mexico will exceed the U.S. population in X years public class Population { public...
Assume that the population of Mexico is 128 million and that the population increases 1.01 percent...
Assume that the population of Mexico is 128 million and that the population increases 1.01 percent annually. Assume that the population of the United States is 323 million and that the population is reduced 0.15 percent annually. Write an application that displays the populations for the two countries every year until the population of Mexico exceeds that of the United States, and display The population of Mexico will exceed the U.S. population in X years The answer should look like...
Assume that the population of Mexico is 128 million and that the population increases 1.01 percent...
Assume that the population of Mexico is 128 million and that the population increases 1.01 percent annually. Assume that the population of the United States is 323 million and that the population is reduced 0.15 percent annually. Write an application that displays the populations for the two countries every year until the population of Mexico exceeds that of the United States, and display The population of Mexico will exceed the U.S. population in X years. the answer should look something...
1)Suppose that inflation in the US is 2 percent and 10 percent in Mexico. Suppose Mexico...
1)Suppose that inflation in the US is 2 percent and 10 percent in Mexico. Suppose Mexico is expected to experience a 5% real depreciation against the US. What is the expected rate of nominal appreciation or depreciation of the peso relative to the dollar? 2) Consider a world with two countries, the United States and Europe.Prices are perfectly flexible and APPP holds at all times. The money supply at this moment in the United States is $1,000,000, real output in...
Assume that you have $100 million dollars to invest in Mexico. Explain where and how you...
Assume that you have $100 million dollars to invest in Mexico. Explain where and how you would invest this capital. What industry would you choose to invest in? How would you structure the investment (new venture, purchase an existing business, joint venture, etc.) Assume that you are presenting to prospective shareholders in your investment company. What factors will influence the expected return on your investment? Present an optimistic scenario, realistic scenario, and pessimistic scenario.
Sora Industries has 67 million outstanding shares, $128 million in debt, $55 million in cash, and...
Sora Industries has 67 million outstanding shares, $128 million in debt, $55 million in cash, and the following projected free cash flow for the next four years: Year 0 1 2 3 4 Earnings and FCF Forecast ($ million) 1 Sales 433.0 468.0 516.0 547.0 574.3 2 Growth vs. Prior Year 8.1% 10.3% 6.0% 5.0% 3 Cost of Goods Sold (313.6) (345.7) (366.5) (384.8) 4 Gross Profit 154.4 170.3 180.5 189.5 5 Selling, General, & Admin. (93.6) (103.2) (109.4) (114.9)...
In 2016, 59.7 percent of the adult population (253 million) was employed. If the employment rate increased to 62 percent,
In 2016, 59.7 percent of the adult population (253 million) was employed. If the employment rate increased to 62 percent,Instructions: In part a, round your response to one decimal place. In part b, enter your response as a whole number.a. How many more people would be working?______ millionb. By how much would output increase if per worker GDP were $122,000?$ _____ billion
Ozone Population 126 0.6 135 3.9 124 0.2 128 0.5 130 2.3 128 0.7 126 1.1...
Ozone Population 126 0.6 135 3.9 124 0.2 128 0.5 130 2.3 128 0.7 126 1.1 We wish to study the effect that the size of various U.S. cities have over ozone concentrations. The size of the populations correspond to the last census (in millions of inhabitants), and the average quantity of ozone per hour was determined in (parts per thousand millions); a) Identify the variables X and Y and analyze if the variables are linearly related. b) Determine the...
4.Assume that more corn is needed because population increases as time passes. Does the share of...
4.Assume that more corn is needed because population increases as time passes. Does the share of total output received by landlords increase, decrease, or remain the same as population increases? Explain your answer. 5.Does the share of total output (or income) received by owners of capital increase, decrease, or remain the same as population increases? Explain your answers. 6. According to Ricardo, will the rate of profit on the poorest grade of farmed land be lower than the rate of...
Assume that $1.4 million is deposited into a bank with a reserve requirement of 15 percent....
Assume that $1.4 million is deposited into a bank with a reserve requirement of 15 percent. Instructions: Round your answer to two decimal places. a. What is the money supply as a result?      b. If the government decides to raise the reserve requirement to 20 percent, what is the value of the money supply in this case?    
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT