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

Need help writing code for this in command prompt . Instructions to follow: The

ID: 3546923 • Letter: N

Question

Need help writing code for this in command prompt.

Instructions to follow:

The population of a town A is less than the population of town B. However, the population of town A is growing faster than the populate 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 A will be greater than or equal to the population of town Band the populations of both the towns at that time. (A sample input is: Population of town A = 5,000, growth rate of town A = 4%, population of town B = 8,000, and growth rate of town B = 2%.)

Explanation / Answer

import java.util.Scanner;

public class Population {

static private int popA;

static private int popB;

static private int grA;

static private int grB;

public static void main(String[] args) {

System.out.println("############QuirkySheep4700############");

Scanner input = new Scanner(System.in);

System.out.print("Enter population of City A:");

popA=input.nextInt();

System.out.print("Enter growth rate of City A:");

grA=input.nextInt();

System.out.print("Enter population of City B:");

popB=input.nextInt();

System.out.print("Enter growth rate of City B:");

grB=input.nextInt();

int year=1;

while(year<100 && popA<popB){

popA=popA+((popA*grA)/100);

popB=popB+((popB*grB)/100);

System.out.println("Year : "+year+" Population of city A : "+popA+" Population of city B : "+popB);

year=year+1;

}

}

}

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