Advertisement
advictoriam

Untitled

Nov 28th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    A program that prompts for the present value, interest rate,
  5.    and number of years for a certificate of deposit to mature,
  6.    and then prints the present value.  
  7.    All variables should be of type double.
  8. */
  9. public class CDWorth
  10. {
  11.    public static void main (String[] args)
  12.    {
  13.       // Display prompt for present value
  14.       System.out.print("Please enter the amount to be deposited: ");
  15.  
  16.       // Read height of rectangle
  17.       Scanner in = new Scanner(System.in);
  18.       double presentVal = in.nextDouble();
  19.  
  20.       // Display prompt for interest rate
  21.       System.out.print("Please enter the rate of interest: ");
  22.  
  23.       // Read rate of interest
  24.       double intRate = in.nextDouble();
  25.  
  26.       // Display prompt for number of years
  27.       System.out.print("Please enter the number of years: ");
  28.  
  29.       // Read number of years
  30.       int years = in.nextInt();
  31.  
  32.       // Compute and print future value
  33.       double futureVal = presentVal*Math.pow(1+(intRate/100), years);
  34.       System.out.printf("%.2f\n", futureVal);
  35.    }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement