- import java.util.Date;
- import javax.swing.JFrame;
- /**
- * This class will calculate the account information of a retirement account
- * for a particular year.
- */
- public class RetirementCalculator extends AccountInformation
- {
- /**
- * Creates an AccountInformation Array.
- * @param start The year's starting balance of this retirement account.
- * @param contrib The year's contribution to this retirement account.
- * @param retire The Year's till retirement to this retirement account.
- * @param interest The year's earned interest of this retirement account.
- */
- public static AccountInformation[] retirementCalc(double start, double contrib, int retire, double interest)
- {
- AccountInformation[] accountInfo = new AccountInformation[retire];
- /////////////////////////////////////////////
- // Member Variables //
- /////////////////////////////////////////////
- /** The Ending balance of the account for this year. */
- double endingBalance;
- /** The Contributed amount of the account for this year. */
- double contribAdded;
- /** The Interest Earned of the account for this year. */
- double interestEarned;
- /** The starting balance of the account for this year. */
- double startingBalance = start;
- //
- /** The loop to place the content into the array. */
- for(int i = 0; i<accountInfo.length; i++)
- {
- // code to compute how much money is added each year.
- endingBalance = (startingBalance + contrib) *(1+(interest));
- contribAdded = contrib;
- interestEarned = (start+contrib) *(interest);
- // Date object to format the time nicely
- Date informationDateStamp = new Date();
- AccountInformation info = new AccountInformation(startingBalance, endingBalance, contribAdded, interestEarned, informationDateStamp );
- //AccountInformation info = new AccountInformation(startBalance, endBalance, contribution, interestEarned, informationDateStamp );
- accountInfo[i] = info;
- startingBalance = endingBalance;
- }
- // returns the array accountInfo
- return(accountInfo);
- }
- // this is our main.
- public static void main (String[] args)
- {
- JFrame frame = new JFrame ("Accountinfo");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- AccountPanel panel = new AccountPanel();
- frame.getContentPane().add(panel);
- frame.pack();
- frame.setVisible(true);
- // assigning the given values from retirementCalc into AccountInformation array
- // AccountInformation[] values = retirementCalc( 200.0, 1.0, 5, 0.08);
- // loop to print out all the info
- // for(int i=0; i<values.length; i++)
- // {
- // System.out.println(values[i]);
- // }
- }
- }
retirementcalc
By: microhaxo | Date: Apr 13 2009 16:07 | Format: None | Expires: never | Size: 2.68 KB | Hits: 971
Latest pastes
1 hours ago
1 days ago
1 days ago
2 days ago
2 days ago