1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Location
South Florida
Posts
3
Rep Power
0

#### Population Projection

Hello All,

I have been asked to make a program that will calculate a the population over the next 5 years.

I have been trying to get this but it seems I am off by one each year as the calculation goes.

Can someone point me in the right direction of what I am doing wrong? I tried to adjust the datatype but was not able to get a better answer.

My answer I am getting is
314812582
317592678
320372774
323152870
325932966

Code:
```public class Population
{ public static void main(String[] args)
{
int currentPopulation = 312032486;
int secondsInYear = 60 * 60 * 24 * 365;
int birthsPerYear = secondsInYear / 7;
int deathsPerYear = secondsInYear / 13;
int immigrantPerYear = secondsInYear / 45;
int perYearAdditions = birthsPerYear - deathsPerYear + immigrantPerYear;
int yearOnePopulation = currentPopulation + perYearAdditions;

System.out.println(yearOnePopulation);
}
}```
thanks

Jerry
2. Can you add some comments to the program's output and say what the output should be?
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Location
South Florida
Posts
3
Rep Power
0
Originally Posted by NormR
Can you add some comments to the program's output and say what the output should be?
The programs results should match the following outputs:
314812582
317592679
320372776
323152873
325932970

I seem to be off by one per year but I dont see why.

I also looked at rewriting without variables
Code:
`System.out.println(((60 * 60 * 24 * 365) / 7) - ((60 * 60 * 24 * 365) / 13) + ((60 * 60 * 24 * 365) / 45) + 312032486);`
this would output the first year but I would still need to complete this for the following 4 years.
4. You make it hard to compare the program's output to the desired output by not putting them close to each other.

5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Location
South Florida
Posts
3
Rep Power
0
I was able to find my errors. It was suggested to me to do it with out variables to remove the datatype issues.

Code:
```public class Population {
public static void main(String[] args) {
System.out.println(((60 * 60 * 24 * 365) / 7) - ((60 * 60 * 24 * 365) / 13) + ((60 * 60 * 24 * 365) / 45) + 312032486);
System.out.println((2 *(60 * 60 * 24 * 365) / 7) - 2 *((60 * 60 * 24 * 365) / 13) + 2 *((60 * 60 * 24 * 365) / 45) + 312032486);
System.out.println((3 *(60 * 60 * 24 * 365) / 7) - 3 *((60 * 60 * 24 * 365) / 13) + 3 *((60 * 60 * 24 * 365) / 45) + 312032486);
System.out.println((4 *(60 * 60 * 24 * 365) / 7) - 4 *((60 * 60 * 24 * 365) / 13) + 4 *((60 * 60 * 24 * 365) / 45) + 312032486);
System.out.println((5 *(60 * 60 * 24 * 365) / 7) - 5 *((60 * 60 * 24 * 365) / 13) + 5 *((60 * 60 * 24 * 365) / 45) + 312032486);
}
}```
6. Makes for ugly code.