In: Computer Science
The population growth for Norway is:
1 birth every 1 minutes and 40 seconds
1 death every 3 minutes and 16 seconds
1 arrival every 57 seconds
1 departure every 1 minute and 49 seconds
Assume the current population is 35,201,142. Write a program that calculates the population n minutes from now. Declare a final integer called minutesElapsed and perform your calculations based on that
/*******************************CurrentPopulation.java*****************************/
public class CurrentPopulation {
public static void main(String[] args) {
final int minutesElapsed =
140;
final int BIRTH_TIME = 100; //
birth in second
final int DEATH_TIME = 196; //
death in second
final int ARRIVAL_TIME = 57; //
Arrival in second
final int DEPARTURE_TIME = 109; //
departure in second
int currentPopulation = 35201142;
// current population
int secondElapsed = minutesElapsed * 60; // elapsed time in second
int birth = secondElapsed /
BIRTH_TIME;// calculate births
int death = secondElapsed /
DEATH_TIME; // calculate deaths
int arrival = secondElapsed /
ARRIVAL_TIME; // calculate arrivals
int departure = secondElapsed /
DEPARTURE_TIME; // calculate departures
currentPopulation = currentPopulation + birth - death + arrival - departure;
System.out
.println("Current Population of Norway after " +
minutesElapsed + " Minutes is: " + currentPopulation);
}
}
/***************************************output************************************/
Current Population of Norway after 140 Minutes is: 35201254
Please let me know if you have any doubt or modify the answer, Thanks :)