Guest User

Untitled

a guest
Dec 11th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. public class CompoundInterest
  2. {
  3.     public static void main(String[]args)
  4.     {
  5.  
  6.         final int STARTRATE = 10;
  7.         final int NRATES = 6;
  8.         final int NYEARS = 10;
  9.  
  10.         double [] interestRate = new double[NRATES];
  11.         for( int j = 0;j<interestRate.length;j++)
  12.             interestRate[j] = (STARTRATE + j)/100.0;
  13.  
  14.         double[][] balances = new double[NYEARS][NRATES];
  15.  
  16.         for(int j = 0;j<balances[0].length;j++)
  17.             balances[0][j] = 10000;
  18.  
  19.         for(int i = 1;i<balances.length;i++)
  20.         {
  21.             for (int j = 0;j<balances.length;i++)
  22.             {
  23.                 double oldBalance = balances[i-1][j];
  24.                 double  interest = oldBalance * interestRate[j];
  25.                 balances[j] = oldBalance + interest;
  26.  
  27.             }
  28.         }
  29.  
  30.         for(int j = 0;j<interestRate.length;j++)
  31.             System.out.printf("%9.0f%%",100*interestRate[j]);
  32.         System.out.println();
  33.  
  34.         for(double []row:balances)
  35.         {
  36.             for (double b : row)
  37.                 System.out.printf("%10.2f",b);
  38.             System.out.println();
  39.         }
  40.  
  41.     }
  42. }
Add Comment
Please, Sign In to add comment