asking for birth year instead of age now

git-svn-id: svn://anubis/gvsu@466 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2009-11-27 23:06:06 +00:00
parent 4ffa66f5eb
commit 6231771a1a
2 changed files with 9 additions and 7 deletions

View File

@ -119,9 +119,10 @@ class RetirementCalculatorPanel
field = new JTextField(); field = new JTextField();
field.addFocusListener(this); field.addFocusListener(this);
myFields.put("age", field); myFields.put("birth_year", field);
myToolTips.put(field, "Enter your current age."); myToolTips.put(field, "Enter the year you were born in.");
addRow(inner, new JLabel("What is your age?", SwingConstants.RIGHT), addRow(inner, new JLabel("What is your birth year?",
SwingConstants.RIGHT),
field); field);
addRow(inner, makeDivider()); addRow(inner, makeDivider());
@ -310,7 +311,7 @@ class RetirementCalculatorPanel
JTextField tf = (JTextField) comp; JTextField tf = (JTextField) comp;
double val = myModel.getField(key); double val = myModel.getField(key);
tf.setText(String.format( tf.setText(String.format(
key.equals("age") ? "%.0f" : "%.2f", val)); key.equals("birth_year") ? "%.0f" : "%.2f", val));
} }
else if (comp.getClass() == JComboBox.class) else if (comp.getClass() == JComboBox.class)
{ {
@ -349,7 +350,7 @@ class RetirementCalculatorPanel
String endl = "<br/>"; String endl = "<br/>";
String msg = "<html>"; String msg = "<html>";
msg += "Name: " + myNameField.getText() + endl; msg += "Name: " + myNameField.getText() + endl;
msg += "Age: " + fmt("%.0f", "age") + endl; msg += "Birth Year: " + fmt("%.0f", "birth_year") + endl;
msg += "Retirement age: " + fmt("%.0f", "retirement age") + endl; msg += "Retirement age: " + fmt("%.0f", "retirement age") + endl;
msg += "Current income: $" + fmt("%,.02f", "current income") + endl; msg += "Current income: $" + fmt("%,.02f", "current income") + endl;
msg += "Desired annual income: $" + msg += "Desired annual income: $" +

View File

@ -31,7 +31,7 @@ public class RetirementCalculatorModel
setField("employer pension", 0); setField("employer pension", 0);
setField("part time income", 0); setField("part time income", 0);
setField("other income", 0); setField("other income", 0);
setField("age", 30); setField("birth_year", 1980);
setField("retirement age", 65); setField("retirement age", 65);
setField("savings", 0); setField("savings", 0);
setField("life expectancy", 82); setField("life expectancy", 82);
@ -130,7 +130,8 @@ public class RetirementCalculatorModel
private int calculateFiveYearsToRetirement() private int calculateFiveYearsToRetirement()
{ {
double retire_age = getField("retirement age"); double retire_age = getField("retirement age");
double current_age = getField("age"); double current_age = Calendar.getInstance().get(Calendar.YEAR) -
getField("birth_year");
double years_to_retirement = retire_age - current_age; double years_to_retirement = retire_age - current_age;
int five_years_to_retirement = int five_years_to_retirement =
(int) ((years_to_retirement + 2.5) / 5.0); (int) ((years_to_retirement + 2.5) / 5.0);