In: Computer Science
Program should be written in Java
a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.) For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated population. Use the JOptionPane Class methods to get user input and to present your output. Make sure that your output is annotated appropriately.
Java Program:
import javax.swing.*;
class PopulationEstimation
{
//Main method
public static void main(String[] args)
{
//Creating frame object
JFrame f = new JFrame();
//Reading current population
long pop2020 =
Long.parseLong(JOptionPane.showInputDialog(f,"Enter the approximate
current population of India: "));
//Predicting population in 2021 and
2022 at growth rate of 1.1%
long pop2021 = pop2020 +
(long)(pop2020*(1.1/100.0));
long pop2022 = pop2021 +
(long)(pop2021*(1.1/100.0));
//Printing results
JOptionPane.showMessageDialog(f,"Year: 2021, Estimated Population:
" + pop2021 + " \nYear: 2022, Estimated Population: " +
pop2022);
}
}
____________________________________________________________________________________________
Sample Run: