Advertisement
binibiningtinamoran

RetirementCalculator

May 26th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RetirementCalculator {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         double averageInterest, amountInvested, endTotal;
  8.         int yearsWait;
  9.  
  10.         Scanner keyboard = new Scanner(System.in);
  11.  
  12.         System.out.println("How much did you invest?");
  13.         amountInvested = keyboard.nextDouble();
  14.  
  15.         while (amountInvested < 1) {
  16.             System.out.println("Amount cannot be negative.");
  17.             System.out.println("How much did you invest? ");
  18.             amountInvested = keyboard.nextDouble();
  19.         }
  20.  
  21.         System.out.println("How many years do you plan to wait before drawing from your account?");
  22.         yearsWait = keyboard.nextInt();
  23.         while (yearsWait < 1) {
  24.             System.out.println("Years cannot be negative.");
  25.             System.out.println("How many years do you plan to wait before drawing from your account?");
  26.             yearsWait = keyboard.nextInt();
  27.         }
  28.  
  29.         System.out.println("What is the average expected rate of interest?");
  30.         averageInterest = keyboard.nextDouble();
  31.         while (averageInterest < 0) {
  32.             System.out.println("Average interest cannot be negative.");
  33.             System.out.println("What is the average expected rate of interest?");
  34.             averageInterest = keyboard.nextDouble();
  35.         }
  36.  
  37.         endTotal = amountInvested * Math.pow((1 + averageInterest), yearsWait);
  38.  
  39.         System.out.printf("After waiting %,d years, your investment will yield $%,2f.", yearsWait
  40.                 , endTotal);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement