Advertisement
kamandos

HW4

Jun 26th, 2022
948
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.  public static void main(String[] args) {
  6.     Scanner in = new Scanner(System.in);
  7.    
  8.     System.out.print("investments: ");
  9.     double investment = in.nextDouble();
  10.    
  11.     System.out.print("interests: ");
  12.     double rate = in.nextDouble();
  13.    
  14.     System.out.print("years: ");
  15.     int year = in.nextInt();
  16.    
  17.     rate *= 0.01;
  18.    
  19.     System.out.println("Years in Future Value");
  20.     for(int i = 1; i <= year; i++) {
  21.         int formatter = 19;
  22.         if (i >= 10) formatter = 18;
  23.         System.out.printf(i + "%"+formatter+".2f\n", FutureValue(investment, rate/12, i));
  24.        }
  25.      }
  26.  
  27.  public static double FutureValue(double investmentAmount, double monthlyInterestRate, int years) {
  28.         return investmentAmount * Math.pow(1 + monthlyInterestRate, years * 12);
  29.     }
  30.    
  31. }
Advertisement
RAW Paste Data Copied
Advertisement