Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- A program that prompts for the present value, interest rate,
- and number of years for a certificate of deposit to mature,
- and then prints the present value.
- All variables should be of type double.
- */
- public class CDWorth
- {
- public static void main (String[] args)
- {
- // Display prompt for present value
- System.out.print("Please enter the amount to be deposited: ");
- // Read height of rectangle
- Scanner in = new Scanner(System.in);
- double presentVal = in.nextDouble();
- // Display prompt for interest rate
- System.out.print("Please enter the rate of interest: ");
- // Read rate of interest
- double intRate = in.nextDouble();
- // Display prompt for number of years
- System.out.print("Please enter the number of years: ");
- // Read number of years
- int years = in.nextInt();
- // Compute and print future value
- double futureVal = presentVal*Math.pow(1+(intRate/100), years);
- System.out.printf("%.2f\n", futureVal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement