Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 10th, 2013, 02:19 AM
yourownreality yourownreality is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Location: South Florida
Posts: 3 yourownreality User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 25 sec
Reputation Power: 0
Homework - 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);  
System.out.println(yearOnePopulation + perYearAdditions); 
System.out.println(yearOnePopulation + (perYearAdditions * 2)); 
System.out.println(yearOnePopulation + (perYearAdditions * 3)); 
System.out.println(yearOnePopulation + (perYearAdditions * 4)); 
} 
}


thanks

Jerry

Reply With Quote
  #2  
Old February 10th, 2013, 06:02 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Can you add some comments to the program's output and say what the output should be?

Reply With Quote
  #3  
Old February 10th, 2013, 06:31 PM
yourownreality yourownreality is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Location: South Florida
Posts: 3 yourownreality User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 25 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
  #4  
Old February 10th, 2013, 06:36 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
You make it hard to compare the program's output to the desired output by not putting them close to each other.

For easier testing start with a simple starting population like 10000.

Reply With Quote
  #5  
Old February 10th, 2013, 07:06 PM
yourownreality yourownreality is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Location: South Florida
Posts: 3 yourownreality User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 25 sec
Reputation 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); 
} 
}

Reply With Quote
  #6  
Old February 10th, 2013, 07:38 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Makes for ugly code.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Population Projection

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap