Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- A program that reads in an interest rate and creates a table of
- future values of a one-thousand dollar certificate of deposit
- for that interest rate and different numbers of years.
- All variables should be of type double, except for the number of years.
- */
- public class CDTable
- {
- public static void main (String[] args)
- {
- // Display prompt for interest rate
- System.out.print("Please enter the rate of interest: ");
- // Read interest rate
- Scanner in = new Scanner(System.in);
- double rate = in.nextDouble();
- int years = 0;
- double presentVal = 1000.00;
- System.out.printf("%2d %7.2f\n", years, presentVal);
- // Print out different values for different years
- years = 5;
- double futureVal = presentVal*Math.pow(1+(rate/100), years);
- System.out.printf("%2d %7.2f\n", years, futureVal);
- years = 10;
- futureVal = presentVal*Math.pow(1+(rate/100), years);
- System.out.printf("%2d %7.2f\n", years, futureVal);
- years = 15;
- futureVal = presentVal*Math.pow(1+(rate/100), years);
- System.out.printf("%2d %7.2f\n", years, futureVal);
- years = 20;
- futureVal = presentVal*Math.pow(1+(rate/100), years);
- System.out.printf("%2d %7.2f\n", years, futureVal);
- years = 25;
- futureVal = presentVal*Math.pow(1+(rate/100), years);
- System.out.printf("%2d %7.2f\n", years, futureVal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement