From edfc5a9b314a6afdaf30a6109136ffc2d9214cd8 Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 5 Oct 2009 02:25:50 +0000 Subject: [PATCH] filled in calculate() git-svn-id: svn://anubis/gvsu@445 45c1a28c-8058-47b2-ae61-ca45b979098e --- cs623/proj1/RetirementCalculatorModel.java | 42 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/cs623/proj1/RetirementCalculatorModel.java b/cs623/proj1/RetirementCalculatorModel.java index 027180d..3efba33 100644 --- a/cs623/proj1/RetirementCalculatorModel.java +++ b/cs623/proj1/RetirementCalculatorModel.java @@ -42,6 +42,25 @@ public class RetirementCalculatorModel public void calculate() { setField("social security", calculateSocialSecurity()); + setField("amount to make up", + getField("income wanted") - + getField("social security") - + getField("employer pension") - + getField("part time income") - + getField("other income")); + setField("amount to save", + getField("amount to make up") * calculateMakeUpFactor()); + setField("early retirement penalty", + getField("social security") * calculateEarlyRetirementFactor()); + setField("estimated savings", + getField("savings") * calculateSavingsFactor()); + setField("total additional savings needed", + getField("amount to save") + + getField("early retirement penalty") - + getField("estimated savings")); + setField("annual savings needed", + getField("total additional savings needed") * + calculateTotalSavingsFactor()); } private double calculateMakeUpFactor() @@ -71,7 +90,7 @@ public class RetirementCalculatorModel return makeup_factors[retire_age_index * 6 + life_expectancy_index]; } - private double calculateRetirementFactor() + private double calculateEarlyRetirementFactor() { int retire_age_index = (int) getField("retirement age"); if (retire_age_index == 55) return 8.8; @@ -92,10 +111,23 @@ public class RetirementCalculatorModel private double calculateSavingsFactor() { - return 0.0; + int savings_factor_index = calculateFiveYearsToRetirement() - 2; + double savings_factors[] = { + 1.3, 1.6, 1.8, 2.1, 2.4, 2.8, 3.3 + }; + return savings_factors[savings_factor_index]; } private double calculateTotalSavingsFactor() + { + int total_savings_factor_index = calculateFiveYearsToRetirement() - 2; + double total_savings_factors[] = { + 0.085, 0.052, 0.036, 0.027, 0.020, 0.016, 0.013 + }; + return total_savings_factors[total_savings_factor_index]; + } + + private int calculateFiveYearsToRetirement() { double retire_age = getField("retirement age"); double current_age = getField("age"); @@ -106,10 +138,6 @@ public class RetirementCalculatorModel five_years_to_retirement = 2; if (five_years_to_retirement > 8) five_years_to_retirement = 8; - int total_savings_factor_index = five_years_to_retirement - 2; - double total_savings_factors[] = { - 0.085, 0.052, 0.036, 0.027, 0.020, 0.016, 0.013 - }; - return total_savings_factors[total_savings_factor_index]; + return five_years_to_retirement; } }