(Population projection) The U.S. Census Bureau projects population based on the
following assumptions:
■ One birth every 7 seconds
■ One death every 13 seconds
■ One new immigrant every 45 seconds
Write a program to display the population for each of the next five years. Assume the
current population is 312,032,486 and one year has 365 days. Hint: In Java, if two
integers perform division, the result is an integer. The fractional part is truncated. For
example, 5 / 4 is 1 (not 1.25) and 10 / 4 is 2 (not 2.5). To get an accurate result with
the fractional part, one of the values involved in the division must be a number with a
decimal point. For example, 5.0 / 4 is 1.25 and 10 / 4.0 is 2.5.
Answer
//Program - 11
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Population projection");
System.out.println("Current population: 312032486");
System.out.println("One birth every 7 seconds.");
System.out.println("One death every 13 seconds.");
System.out.println("One new immigrant every 45 seconds.");
System.out.println("Yearly Population projection formula: ");
System.out.println("Current population + ((births per year)");
System.out.println(" - (deaths per year)");
System.out.println(" + (new immigrants per year))");
System.out.println(" * year.");
System.out.println("Year 1 projection: ");
System.out.println(312032486 + (((31536000 / 7)
- (31536000 / 13)
+ (31536000 / 45)) * 1));
System.out.println("Year 2 projection: ");
System.out.println(312032486 + (((31536000 / 7)
- (31536000 / 13)
+ (31536000 / 45)) * 2));
System.out.println("Year 3 projection: ");
System.out.println(312032486 + (((31536000 / 7)
- (31536000 / 13)
+ (31536000 / 45)) * 3));
System.out.println("Year 4 projection: ");
System.out.println(312032486 + (((31536000 / 7)
- (31536000 / 13)
+ (31536000 / 45)) * 4));
System.out.println("Year 5 projection: ");
System.out.println(312032486 + (((31536000 / 7)
- (31536000 / 13)
+ (31536000 / 45)) * 5));
}
}
OUTPUT
Population projection
Current population: 312032486
One birth every 7 seconds.
One death every 13 seconds.
One new immigrant every 45 seconds."
Yearly Population projection formula:
Current population + ((births per year)
- (deaths per year)
+ (new immigrants per year))
* year.
Year 1 projection:
314812582
Year 2 projection:
317592678
Year 3 projection:
320372774
Year 4 projection:
323152870
Year 5 projection:
325932966
If you have any doubts or questions, please let me know.