diff --git a/cs623/proj1/RetirementCalculator.java b/cs623/proj1/RetirementCalculator.java index 5092c8d..750e146 100644 --- a/cs623/proj1/RetirementCalculator.java +++ b/cs623/proj1/RetirementCalculator.java @@ -311,9 +311,44 @@ class RetirementCalculatorPanel extends JPanel implements ActionListener myResultBox.setText(" "); } + private String fmt(String fmt, String field) + { + return String.format(fmt, myModel.getField(field)); + } + private void print() { calculate(); + String endl = "
"; + String msg = ""; + msg += "Name: " + myNameField.getText() + endl; + msg += "Current income: $" + fmt("%.02f", "current income") + endl; + msg += "Desired annual income: $" + + fmt("%.02f", "income wanted") + endl; + msg += endl; + msg += "Social Security benefit: $" + + fmt("%.02f", "social security") + endl; + msg += "Traditional Employer Pension: $" + + fmt("%.02f", "employer pension") + endl; + msg += "Part-time income: $" + fmt("%.02f", "part time income") + endl; + msg += "Other income: $" + fmt("%.02f", "other income") + endl; + msg += "Amount to make up each retirement year: $" + + fmt("%.02f", "amount to make up") + endl; + msg += endl; + msg += "Total amount to save: $" + + fmt("%.02f", "amount to save") + endl; + msg += "Early retirement addition: $" + + fmt("%.02f", "early retirement penalty") + endl; + msg += "Estimated savings at retirement: $" + + fmt("%.02f", "estimated savings") + endl; + msg += endl; + msg += "Total additional savings needed at retirement: $" + + fmt("%.02f", "total additional savings needed") + endl; + msg += "Required annual savings: $" + + fmt("%.02f", "annual savings needed") + endl; + msg += ""; + JOptionPane.showMessageDialog(null, msg, + "Basic Retirement Calculator", JOptionPane.PLAIN_MESSAGE); } }