Java Programming control structures:\ The population of Town A is less than the population of Town . However, the population of Town A is growing faster than the population of Town B. Write a program that prompts the user to enter the population and growth rate of each town. The program outputs after how many years the population of Town Aa will be greater than or equal to the population of Town B and the populations of both towns at that time. Sample input is: Population of Town A = 5,000, growth rate of town A =4%, populatio of Town B = 8,000, and growth rate of town B = 2%

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Java Programming control structures:\

The population of Town A is less than the population of Town . However, the population of Town A is growing faster than the population of Town B. Write a program that prompts the user to enter the population and growth rate of each town. The program outputs after how many years the population of Town Aa will be greater than or equal to the population of Town B and the populations of both towns at that time. Sample input is: Population of Town A = 5,000, growth rate of town A =4%, populatio of Town B = 8,000, and growth rate of town B = 2%

Here's my code and something is not right

static Scanner console = new Scanner(System.in);
public static void main(String[] args) {

int populationA;
int populationB;
int projectedYears;
int futurePopulation;
double townAGrowthRate;
double townBGrowthRate;

System.out.print("Enter the population for Town A and Town B "
+ "(population of Town A should be less than Town B): \n");

populationA = console.nextInt();
populationB = console.nextInt();

System.out.print("Enter the growth rate for Town A and Town B "
+ "(growth rate of Town B should less Town A: \n");

townAGrowthRate = console.nextDouble();
townBGrowthRate = console.nextDouble();

System.out.print("Enter the number of years to calculate the future population growth: \n");

projectedYears = console.nextInt();

int countYears = 0;

//Calculate thw future population of own A and town B
if(populationA < populationB && townAGrowthRate > townBGrowthRate)
{
do{
populationA = (int) ((townAGrowthRate / 100) * populationA) + (populationA);
populationB = (int) ((townBGrowthRate / 100) * populationB) + (populationB);
countYears++;
// System.out.println(" Town A" + populationA);
//System.out.println("Town B" + populationB);
}while(countYears < projectedYears && populationA < populationB );

}

System.out.print("Town A's population will be greater than or equal to Town B's population "
+ " in " + countYears + " years \n");
System.out.print("The population of Town A in " + countYears + " "
+ " years will be: " + populationA + "\n");
System.out.print("The population of Town B in " + countYears + " "
+ "years will be: " + populationB + "\n");


//else{
// System.out.print("Invalid Entry \n");
//}
/*
* Town APopulaton = 5000
* Town A Growth Rate = .04%
* Town B Population = 8000
* Town B Growth Rate = .02%
*
* Enter the population for Town A and Town B (population of Town A should be less than Town B): 10 1000
* Enter the growth rate for Town A and Town B (growth rate of Town B should less Town A: 15 20.5
* Enter the projected number of years:
*
*
* Run on 10/23/19
*
* //Calculate thw future population of own A and town B
if(populationA < populationB && townAGrowthRate > townBGrowthRate)
{
do{
townAPopulation = (int) ((townAGrowthRate / 100) * populationA) + (populationA);
townBPopulation = (int) ((townBGrowthRate / 100) * populationB) + (populationB);
countYears++;
// System.out.println(" Town A" + populationA);
//System.out.println("Town B" + populationB);
}while(countYears < projectedYears && populationA < populationB );


*
*
* Enter the population for Town A and Town B (population of Town A should be less than Town B):
5000 8000
Enter the growth rate for Town A and Town B (growth rate of Town B should less Town A:
.04 .02
Enter the number of years to calculate the future population growth:
10
Town A's population will be greater than or equal to Town B's population in 10 years
The population of Town A in 10 years will be: 5002
The population of Town B in 10 years will be: 8001
*/

}
}

Thank you

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education