Advertisement
advictoriam

Untitled

Nov 28th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    A program that reads in an interest rate and creates a table of
  5.    future values of a one-thousand dollar certificate of deposit
  6.    for that interest rate and different numbers of years.
  7.    All variables should be of type double, except for the number of years.
  8. */
  9. public class CDTable
  10. {
  11.    public static void main (String[] args)
  12.    {
  13.       // Display prompt for interest rate
  14.       System.out.print("Please enter the rate of interest: ");
  15.  
  16.       // Read interest rate
  17.       Scanner in = new Scanner(System.in);
  18.       double rate = in.nextDouble();
  19.  
  20.       int years = 0;
  21.       double presentVal = 1000.00;
  22.      
  23.       System.out.printf("%2d %7.2f\n", years, presentVal);
  24.  
  25.       // Print out different values for different years
  26.       years = 5;
  27.       double futureVal = presentVal*Math.pow(1+(rate/100), years);
  28.       System.out.printf("%2d %7.2f\n", years, futureVal);
  29.      
  30.       years = 10;
  31.       futureVal = presentVal*Math.pow(1+(rate/100), years);
  32.       System.out.printf("%2d %7.2f\n", years, futureVal);
  33.      
  34.       years = 15;
  35.       futureVal = presentVal*Math.pow(1+(rate/100), years);
  36.       System.out.printf("%2d %7.2f\n", years, futureVal);
  37.      
  38.       years = 20;
  39.       futureVal = presentVal*Math.pow(1+(rate/100), years);
  40.       System.out.printf("%2d %7.2f\n", years, futureVal);
  41.      
  42.       years = 25;
  43.       futureVal = presentVal*Math.pow(1+(rate/100), years);
  44.       System.out.printf("%2d %7.2f\n", years, futureVal);
  45.    }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement