Public paste
retirementcalc
By: microhaxo | Date: Apr 13 2009 16:07 | Format: None | Expires: never | Size: 2.68 KB | Hits: 971

  1. import java.util.Date;
  2. import javax.swing.JFrame;
  3. /**
  4.  * This class will calculate the account information of a retirement account
  5.  * for a particular year.
  6.  */
  7. public class RetirementCalculator extends AccountInformation
  8. {
  9.          /**
  10.      * Creates an AccountInformation Array.
  11.      * @param start The year's starting balance of this retirement account.
  12.      * @param contrib The year's contribution to this retirement account.
  13.           * @param retire The Year's till retirement to this retirement account.
  14.      * @param interest The year's earned interest of this retirement account.
  15.      */
  16.         public static AccountInformation[] retirementCalc(double start, double contrib, int retire, double interest)
  17.         {
  18.                 AccountInformation[] accountInfo = new AccountInformation[retire];
  19.                  /////////////////////////////////////////////
  20.          //            Member Variables             //
  21.          /////////////////////////////////////////////
  22.                  /** The Ending balance of the account for this year. */
  23.                 double endingBalance;
  24.                  /** The Contributed amount of the account for this year. */
  25.                 double contribAdded;
  26.                  /** The Interest Earned of the account for this year. */
  27.                 double interestEarned;
  28.                  /** The starting balance of the account for this year. */
  29.                 double startingBalance = start;
  30.                 //
  31.                
  32.                
  33.                
  34.        
  35.                  /** The loop to place the content into the array. */
  36.                 for(int i = 0; i<accountInfo.length; i++)
  37.                 {
  38.                         // code to compute how much money is added each year.
  39.                         endingBalance = (startingBalance + contrib) *(1+(interest));
  40.                         contribAdded = contrib;
  41.                         interestEarned = (start+contrib) *(interest);
  42.                        
  43.                         // Date object to format the time nicely
  44.                         Date informationDateStamp = new Date();
  45.                         AccountInformation info = new  AccountInformation(startingBalance, endingBalance,  contribAdded, interestEarned, informationDateStamp );
  46.                         //AccountInformation info = new  AccountInformation(startBalance, endBalance,  contribution, interestEarned, informationDateStamp );
  47.                         accountInfo[i] = info;
  48.                         startingBalance = endingBalance;
  49.                 }
  50.                 // returns the array accountInfo
  51.                 return(accountInfo);
  52.         }      
  53.  
  54.         // this is our main.
  55.         public static void main (String[] args)
  56.         {      
  57.                 JFrame frame = new JFrame ("Accountinfo");
  58.                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  59.                 AccountPanel panel = new AccountPanel();
  60.                 frame.getContentPane().add(panel);
  61.                 frame.pack();
  62.                 frame.setVisible(true);
  63.                 // assigning the given values from retirementCalc into AccountInformation array
  64.          //     AccountInformation[] values = retirementCalc( 200.0, 1.0, 5, 0.08);
  65.                 //      loop to print out all the info
  66.          //     for(int i=0; i<values.length; i++)
  67.         //      {
  68.                        
  69.         //              System.out.println(values[i]);
  70.           //    }
  71.                
  72.         }
  73. }