forked from HarryDulaney/intro-to-java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExercise02_11.java
33 lines (24 loc) · 1.12 KB
/
Exercise02_11.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package ch_02;
import java.util.Scanner;
/**
* 2.11 (Population projection) Rewrite Programming {@linkplain ch_01.Exercise01_11} to prompt the user
* to enter the number of years and displays the population after the number of years.
* Use the hint in Programming {@linkplain ch_01.Exercise01_11} for this program. The population
* should be cast into an integer.
*/
public class Exercise02_11 {
public static void main(String[] args) {
int currentPopulation = 312_032_486;
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of years to display the population growth: ");
int numberOfYears = input.nextInt();
double secondsInYear = 365 * 24 * 60 * 60;
int birthsPerYear = (int) secondsInYear / 7;
int deathsPerYear = (int) secondsInYear / 13;
int immigrantsPerYear = (int) secondsInYear / 45;
for (int i = 1; i <= numberOfYears; i++) {
currentPopulation += birthsPerYear + immigrantsPerYear - deathsPerYear;
}
System.out.println("The population in " + numberOfYears + " is " + currentPopulation);
}
}