The town of Rien, Ohio currently has a population 9.870. Due to the repent boom
ID: 3677233 • Letter: T
Question
The town of Rien, Ohio currently has a population 9.870. Due to the repent boom in craft breweries in the town, the population has been growing at a rate of 10% per year. The city fathers are concerned about what will happen when the town reaches 30.000 people and the strain that this type of population will put on the public utilities etc. You are to write a program that uses a loop to compute in what year Rien will reach 30.000 people. But you immediately realize that if you made the program more general, allowing a community to enter their current population and their "target" population, they could also use this software. So you are to have the user enter the current year, the current population and target population. It will then display the population for each year, terminating when the target population has been reached or exceeded. (Note that population growth is like compound interest, the "interest" is computed as a percentage of the larger population at the end of each year: pop = pop + pop*growth_r;) It looks something like this: Welcome to Population Projector. Begin by entering the current year => 2015 Now enter your town's current population => 9870 Enter the expected population growth as a percentage => 10 Now enter the target population => 30000 Your program should have a comment block at the top of the program which includes your name and some information about the program. It should work for any year or populationExplanation / Answer
import java.util.Scanner;
public class PopluationProjector
{
public static void main(String args[])
{
/* The Population Projector for printing population growth according corresponding year by given growth rate until target population given by user*/
System.out.println("Welcome to the Population Projector");
//reading current year and population ,growth values entered by user from keyboard
Scanner in = new Scanner(System.in);
System.out.printf("Begin by the entering current year => ");
int y = in.nextInt();
System.out.println("Now enter’s your towns current population => ");
int p = in.nextInt();
System.out.println("Enter the expected population Growth as a percentage => ");
int g = in.nextInt();
System.out.println("Now enter the target population => ");
int tp= in.nextInt();
int i;
/*initiate for loop staring I from the current year and it runs until target population reached by incrementing the year*/
for(i=y;p>=tp;i++)
{
System.out.println(i+" "+ p);
//population=current population Current population*growth rate
p=p+p*g;
if(p>tp)
{
System.out.println(" In the year "+i+"you will exceed your target of"+tp+"with a population of"+p);
}
}
}//main
}//class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.